Error importing schema

Hi all,

I wanted to try out DGraph locally (using the latest Docker standalone version for DGraph) before using Slash Graphql. But I am stuck at altering my schema via the http-js client. When I’m trying to import an example schema I found in the docs I get an error when I run dgraphClient.alter({ schema}):

Expected new line after field declaration. Got @

It seems the client can’t read the @ symbol.

Here is the shema I am trying to import:

type Task {
  id: ID!
  title: String! @search(by: [fulltext])
  completed: Boolean! @search
  user: User!
}

type User {
  username: String! @id @search(by: [hash])
  name: String @search(by: [exact])
  tasks: [Task] @hasInverse(field: user)
}

Am I mixing up the schema definition with a graphQL file?

Thanks in Advance

This schema you are trying to send is a GraphQL one. All Dgraph’s clients are DQL. They don’t support GraphQL. Use Insomnia, postman, or some GraphQL client point to /admin to send that schema.

https://dgraph.io/docs/graphql/admin/#using-adminschema

Thanks a lot @MichelDiz !
So this also means that if I want to have an API layer in between Slash Graphql and my frontend that has a Graphql endpoint I need two schemas? And in the API layer I somehow have to translate Graphql to DQL and vice-versa?

Frontend (/graphql)--> API layer (graphql <-> DQL) --> Slash Graphql

If you have another GraphQL server, you have to find a way to mix them. There is Apollo Federation and we have some engineers working on it. That’s an option for you.

If you wanna have your own GraphQL server that accesses Dgraph, you have to deal with DQL yourself. But Dgraph’s GraphQL feature is an automated GraphQL server based on your schema. So you won’t be bothered with business logic. Dgraph deals with business logic and DQL at the core level.

Slash Graphql is just a hosted service that handles Dgraph and the infrastructure for you.

1 Like

Thanks again!

The thing is I just want to try out DGraph. Usually, I learn new technolgies using TDD and by writing a small test app because the developing workflow and also the possibility to develop locally is very important to me.
So I think I’m just looking for a way to have a (fully) tested & flexible app and then deploy it using Slash Graphql instead of hosting the database myself or using the more expensive pricing plans.

Btw, sorry if I’m hijacking the topic of this thread - maybe I should create a new one with that question.

No problem, feel free to ask. But if you think the topic is good enough to create a new Discourse topic. Please, do. That helps others in the future searching for specific themes.

1 Like