Reputation: 91610
I'm working on a project for which a graph database makes the most sense as storage. My schema is something that I need to be fairly malleable, so I don't want to have to write resolvers up front, so Dgraph, which speaks GraphQL natively, makes a lot of sense during this period of quick iteration.
I've been over the Dgraph docs but I'm having difficulty finding out how to insert a schema into the database. I have tried simply sending a POST request via curl to the /admin endpoint containing my schema, but I get 400s reporting bad requests.
Given a GraphQL schema on disk, how can I upload the schema into Dgraph?
Upvotes: 0
Views: 43
Reputation: 241420
From the Dgraph docs here:
To create a schema you only need to call the
/admin/schema
endpoint with the required schema definition. For example:type Person { name: String }
If you have the schema definition stored in a
schema.graphql
file, you can usecurl
like this:curl -X POST localhost:8080/admin/schema --data-binary '@schema.graphql'
On successful execution, the
/admin/schema
endpoint will give you a JSON response with a success code.
Alternatively, if you are using Dgraph Cloud, you can log in and upload the schema directly through the web interface, as described in step 2 of the quick start docs.
Upvotes: 0