Convert types schema to the actual schema file

Currently, the types.graphql file that holds all the types can be imported into the database.

Exporting the schema will also generate the predicates and the queries/mutations… To do that, it is possible to run a graphql query.

Is it possible to do that without even starting the database? Is there any tool/cli that I can use?

Exporting using the dgraph cloud is also possible, so I guess you guys can generate the schema file without starting the database.

Can you tell me more about your use case? Are you hoping to catch schema changes before spinning up the DB?

Hello, I don’t think that the use case matters here. I can think of many different use cases than mine, but the whole purpose is to have the schema without the need to apply the types in Dgraph first and then export it…

My case is that I need the schema to generate and validate other parts in my infra. Now I start a dgraph, import the types, export the schema, and then kill the db and cleanup…
This is an overkill…

Can you share the part of the dgraph’s code responsible for generating the schema? Perhaps I can use it or is it possible to use a specific dgraph command?

I’m not aware of a public API or CLI to read the schema in the data file at rest, I’ll ask our engineers.
Note that the best practice is to have the schema in source control and deploy it to your environments (DEV, PROD) through your CI/CD. Following this best practice, the schema should be available in source control and you should not have to start a cluster and export to know the schema deployed in a cluster.

Hello Raphael,

Thank you for the response. We already have the schema in source control, but we also have other components that rely on that generated by the dgraph schema.

We searched through your documentation and asked on your Discord server without receiving any answer. Our only solution is to start a standalone dgraph instance, import the schema, export it, and then stop the dgraph instance and clean up.

Can anyone from the engineering team let us know if the code responsible for generating the schema and exporting it is public, so we can write a small tool using your code libraries since your team hasn’t implemented it in the dgraph cli?

@droslean you are talking about the generated GraphQL schema, correct?
That could be a nice contribution to the CLI, indeed.
I’ll ask someone to point you to the right piece of code in the public dgraph repo…