In rest API , we could version our APIS like this :
example.com/api/v1/
And what is the idea when using a single GraphQL endpoint ?
Thanks.
In rest API , we could version our APIS like this :
example.com/api/v1/
And what is the idea when using a single GraphQL endpoint ?
Thanks.
The short version is: You don't :)
The long version is best explained by the GraphQL site:
While there's nothing that prevents a GraphQL service from being versioned just like any other REST API, GraphQL takes a strong opinion on avoiding versioning by providing the tools for the continuous evolution of a GraphQL schema.
Why do most APIs version? When there's limited control over the data that's returned from an API endpoint, any change can be considered a breaking change, and breaking changes require a new version. If adding new features to an API requires a new version, then a tradeoff emerges between releasing often and having many incremental versions versus the understandability and maintainability of the API.
In contrast, GraphQL only returns the data that's explicitly requested, so new capabilities can be added via new types and new fields on those types without creating a breaking change. This has led to a common practice of always avoiding breaking changes and serving a versionless API.
Source: https://graphql.org/learn/best-practices/#versioning
you can do like that
services.AddGraphQLServer("v1").AddQueryType<QueryV1>();
services.AddGraphQLServer("v2").AddQueryType<QueryV2>();
app.UseEndpoints(e =>
{
e.MapGraphQL("/graphql/v1","v1");
e.MapGraphQL("/graphql/v2","v2");
});