Writing schema in Dgraph vs GraphQL

From my understanding, schemas for a Dgraph database can be written in either GraphQL or in Dgraph.
What’s the difference?

Teams already familiar with graphql can use Dgraph in a more intuitive manner as Dgraph supports scalars, types, queries, mutations, introspection and other constructs as mentioned in the graphql spec. They can get into other aspects of Dgraph as and when required.

1 Like

From my understanding, schema predicate directives have to be outside of a type.
Eg you can’t do

type Company {
    name: string @index(fulltext, term) .
}

and instead have to do

type Company {
    name
}
name: string @index(fulltext, term) .

Is this correct?

Yes, that is true. I believe the idea is that the predicates are then available to be reused between types. Please note that the predicates can be a scalar (like legalName) or another entity (like owns).
Some more details are available at this link.

1 Like

Thanks! I see, I guess that can help with avoiding code redundancy.

1 Like

If you are writing DQL schema that will later be used in a graphql endpoint, you will also need to either use dotted type notation such as Contact.name or use the @dql directive in your graphql schema to match up the fields. The digraph.type is imperative to make the graphql endpoint function.

I have found it easier to write the schema once in graphql and then still be able to use it with DQL. Noting that in DQL when calling fields you will need to use the dotted type name for the predicates.

1 Like