graphql-dotnet / conventions

GraphQL Conventions Library for .NET
MIT License
233 stars 63 forks source link

Deprecate execution and serialization code #249

Closed Shane32 closed 1 year ago

Shane32 commented 1 year ago

Changes:

Once the deprecated code is removed, perhaps in a later version, it will greatly reduce the amount of overlapped code between this project and the base project. We will also be able to remove the dependency on GraphQL.NewtonsoftJson.

Although the new setup is a bit more dependent on DI, the server project is compatible with frameworks as far back as ASP.NET Core 2.1 on .NET Framework 4.6.1, through .NET 7, including the latest standards, two subscription protocols, and most recently Azure Functions. It includes has a wide array of configuration options to fit with user requirements.

In addition, going forward, the conventions project can still be used by constructing a schema via GraphQLEngine, and users can utilize GraphQL.NewtonsoftJson or GraphQL.SystemTextJson to deserialize requests and serialize responses, and DocumentExecuter to execute documents. So there really is no loss of functionality even without the server project.

Before

        var requestHandler = RequestHandler
            .New()
            .WithServiceProvider(serviceProvider)
            .WithQueryAndMutation<Query, Mutation>()
            .Generate();

        var request = Request.New(new QueryInput { QueryString = "{ __schema { types { name } } }" });
        var result = await requestHandler.ProcessRequestAsync(request, null, serviceProvider);
        var resultJson = result.GetBody();

After (without DI)

        var schema = GraphQLEngine
            .New()
            .WithQueryAndMutation<Query, Mutation>()
            .GetSchema();
        var executer = new GraphQL.DocumentExecuter();
        var serializer = new GraphQL.SystemTextJson.GraphQLSerializer();

        var ret = await executer.ExecuteAsync(new()
        {
            Schema = schema,
            Query = "{ __schema { types { name } } }",
            RequestServices = serviceProvider,
        });
        var retJson = serializer.Serialize(ret);