Skip to content

Code first schema configuration with AddGraphQL() #1190

Closed Answered by Shane32
sri-s-creator asked this question in Q&A
Discussion options

You must be logged in to vote

Code first implies that you have a class that inherits from GraphQL.Types.Schema - for example like this:

public class StarWarsSchema : Schema
{
    public StarWarsSchema(IServiceProvider serviceProvider)
        : base(serviceProvider)
    {
        Query = serviceProvider.GetRequiredService<StarWarsQuery>();
        Mutation = serviceProvider.GetRequiredService<StarWarsMutation>();

        Description = "Example StarWars universe schema";
    }
}

To register your code-first schema, just use something like this:

builder.Services.AddGraphQL(b => b
    // add your code-first schema class
    .AddSchema<StarWarsSchema>()
    // add the serialization engine to use
    .AddSystemTextJson()
    

Replies: 4 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by sri-s-creator
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@Shane32
Comment options

@sri-s-creator
Comment options

@Shane32
Comment options

@sri-s-creator
Comment options

@Shane32
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants