GraphQL design with @dgraph directive
User needs to define different fields for different language tags that he want to use.
Example:
type Person {
name: String // Person.name is the corresponding dgraph field for this field
nameHi: String @dgraph(pred:"Person.name@hi")
nameEn: String @dgraph(pred:"Person.name@en")
nameHi_En: String @dgraph(pred:"Person.name@hi:en") // won't be added to mutation patch
nameHi_En_untag: String @dgraph(pred:"Person.name@hi:en:.") //won't be added to mutation patch
}
We will add @lang in dgraph schema for the corresponding predicate automatically. User needs to give dgraph predicate name of the untagged field(name in this case) in @dgraph argument of language tag field. Dgraph predicate name for the corresponding graphql field typename.fieldname.
For example, in nameHi: String @dgraph(pred:"Person.name@hi") we have Person.name which is predicate in dgraph for the corresponding field name in graphql. If user give some other field name in argument then it won’t work as expected.
Note
- User needs to define all language fields at one place either in type or in the interface.
- We won’t be adding fields in mutation patch which have multiple language tags , for example field
nameHi_En: String @dgraph(pred:"Person.name@hi:en")can only be queried.
Interaction with exiting directives for language tagged fields:
schema directives
@id : not required now, can be added in future .
@search: applicable only on one field(tagged or untagged value) and will apply on all gql fields which map to the same dgraph predicate.
@lambda: doesn’t work with @dgraph directive
@custom : doesn’t work with @dgraph directive
@hasinverse: doesn’t apply on string fields
query directives
@skip: Work normally as with other fields
@include: Work normally as with other fields