ChilliCream / graphql-workshop

Getting started with GraphQL on ASP.NET Core and Hot Chocolate - Workshop
465 stars 199 forks source link

AddTypeExtension vs AddType #31

Closed gojanpaolo closed 3 years ago

gojanpaolo commented 3 years ago

In 4-schema-design, AddTypeExtension and AddType is used interchangeably. I'm curious as well as confused because of this. I'll probably be able to clarify this later when I get to learn more about graphql and hc. But any response will be greatly appreciated.

e.g.

  1. Head back to the Startup.cs and add the TrackMutations to the schema builder.

    services
        .AddGraphQLServer()
        .AddQueryType(d => d.Name("Query"))
            .AddTypeExtension<SpeakerQueries>()
        .AddMutationType(d => d.Name("Mutation"))
            .AddTypeExtension<SessionMutations>()
            .AddTypeExtension<SpeakerMutations>()
            .AddTypeExtension<TrackMutations>()
        .AddType<AttendeeType>()
        .AddType<SessionType>()
        .AddType<SpeakerType>()
        .AddType<TrackType>()
        .EnableRelaySupport()
        .AddDataLoader<SpeakerByIdDataLoader>()
        .AddDataLoader<SessionByIdDataLoader>();

  1. Again, head over to the Startup.cs and register the TrackQueries with the schema builder.

    services
        .AddGraphQLServer()
        .AddQueryType(d => d.Name("Query"))
            .AddType<SessionQueries>()
            .AddType<SpeakerQueries>()
            .AddType<TrackQueries>()
        .AddMutationType(d => d.Name("Mutation"))
            .AddType<SessionMutations>()
            .AddType<SpeakerMutations>()
            .AddType<TrackMutations>()
        .AddType<AttendeeType>()
        .AddType<SessionType>()
        .AddType<SpeakerType>()
        .AddType<TrackType>()
        .EnableRelaySupport();
michaelstaib commented 3 years ago

So, they actually can be used both ... we are however diverting to use AddTypeExtension to be more semantically correct. There might still be old code examples in the workshop that use AddType instead of AddTypeExtension.

Do you want to do a pull-request?

gojanpaolo commented 3 years ago

@michaelstaib sure 👍

michaelstaib commented 3 years ago

Awesome! Thanks for your help on this!