0

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.

2 Answers2

0

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

Alex
  • 1,425
  • 11
  • 25
  • 1
    Depends on the use case. Shopify has a fantastic GQL implementation and they use versioning. The tradition GQL stance is to use evolution instead of versioning but it's not black & white. – VtoCorleone Nov 30 '22 at 23:08
0

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");
             
            });
Mudasser
  • 29
  • 2
  • Although not very clear from the OP's question this is tagged for Laravel Lighthouse which is a PHP GraphQL server and from the looks of you code it's TS or C# which is not very helpful in this context since we are dealing with a PHP GraphQL server. – Alex Jul 06 '22 at 09:54