# Writing schema in Dgraph vs GraphQL

**URL:** <https://discuss.dgraph.io/t/writing-schema-in-dgraph-vs-graphql/9324>\
**Category:** Dgraph\
**Tags:** graphql, schema, dgraph, help-wanted\
**Created:** [August 10, 2020, 4:44am UTC](https://discuss.dgraph.io/t/writing-schema-in-dgraph-vs-graphql/9324 "2020-08-10T04:44:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorillastanley](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gorillastanley/32/4518_2.png) [@gorillastanley](https://discuss.dgraph.io/u/gorillastanley)\
**Post date:** [August 10, 2020, 4:44am UTC](https://discuss.dgraph.io/t/writing-schema-in-dgraph-vs-graphql/9324/1 "2020-08-10T04:44:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anand](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anand/32/5674_2.png) [@anand](https://discuss.dgraph.io/u/anand)\
**Post date:** [August 10, 2020, 5:00am UTC](https://discuss.dgraph.io/t/writing-schema-in-dgraph-vs-graphql/9324/2 "2020-08-10T05:00:54Z")

</div>

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.](https://spec.graphql.org/June2018/) They can get into other aspects of Dgraph as and when required.

---

<div class="post-metadata">

**Author:** ![gorillastanley](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gorillastanley/32/4518_2.png) [@gorillastanley](https://discuss.dgraph.io/u/gorillastanley)\
**Post date:** [August 10, 2020, 6:17am UTC](https://discuss.dgraph.io/t/writing-schema-in-dgraph-vs-graphql/9324/3 "2020-08-10T06:17:50Z")

</div>

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

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

```

and instead have to do

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

```

Is this correct?

---

<div class="post-metadata">

**Author:** ![anand](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/anand/32/5674_2.png) [@anand](https://discuss.dgraph.io/u/anand)\
**Post date:** [August 10, 2020, 6:34am UTC](https://discuss.dgraph.io/t/writing-schema-in-dgraph-vs-graphql/9324/4 "2020-08-10T06:34:19Z")

</div>

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](https://schema.org/legalName)) or another entity (like [owns](https://schema.org/owns)).  
Some more details are available at this [link](https://dgraph.io/docs/query-language/type-system/).

---

<div class="post-metadata">

**Author:** ![gorillastanley](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gorillastanley/32/4518_2.png) [@gorillastanley](https://discuss.dgraph.io/u/gorillastanley)\
**Post date:** [August 10, 2020, 6:42am UTC](https://discuss.dgraph.io/t/writing-schema-in-dgraph-vs-graphql/9324/5 "2020-08-10T06:42:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [August 10, 2020, 11:34am UTC](https://discuss.dgraph.io/t/writing-schema-in-dgraph-vs-graphql/9324/6 "2020-08-10T11:34:43Z")

</div>

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.
