I am very interested in GraphQL and I am currently working with GraphQL in ASP.NET Core 3.1 using GraphQL for .NET and Relay. It hasn’t been immediately clear what I needed to do in order to get up and running.
If you ignore Relay, things can be a lot easier. There’s a good example in the source for GraphQL.EntityFramework which includes GraphQL subscription too – which is nice. However, if you want to use Relay properly it isn’t immediately obvious that this isn’t currently possible with Entity Framework. If you are aiming to use Relay, this article provides a paging solution using SqlKata.
Having created a GraphQL schema on the server using a code-first approach I was initially a bit confused by the requirement for a
schema.graphql file. For a little time I thought I was going to have to recreate the schema manually, and might have been best going initially with a schema-first approach instead. However, reading How to Retrieve a GraphQL Schema was very helpful, once I discovered that the schema file can be a
.graphql or a
To use the Relay Compiler, you need either a .graphql or .json GraphQL schema file, describing your GraphQL server’s API. Typically these files are local representations of a server source of truth and are not edited directly.https://relay.dev/docs/en/graphql-in-relay.html#graphql-schema
We can use a GraphQL query to get the JSON version of the schema directly from the server endpoint.
Now, with the following
relay-compiler command you can generate the framework that’s required for the Relay queries to work.
relay-compiler --src ./src --schema ./schema.json
This doesn’t replace a step-by-step guide, but a quick summary of some of the important details I found were not clearly noted.
I will write more about GraphQL again later. I think sometimes it is easier when there is a working example to learn from. I will think about providing an example to illustrate a step-by-step guide in more detail, perhaps.