0

I'm trying to create class with enum and I have an error.

public class MarsWheather {
    public Season MarsSeason { get; set; }
}

public enum Season {
    winter,
    spring,
    summer,
    autumn
}

My graphql classes look like:

public class SolSchema : Schema
{
    public SolSchema(IServiceProvider sp) : base(sp)
    {
        Query = sp.GetRequiredService<SolDataQuery>();
        Mutation = sp.GetRequiredService<SolDataMutation>();
    }
}
public class SolDataQuery : ObjectGraphType<object>
{
    public SolDataQuery(INasaProvider nasaProvider)
    {
            Field<MarsWheatherType>("wheather", resolve: context => nasaProvider.GetAsync());
    }
}
public class MarsWheatherType : ObjectGraphType<MarsWheather>
{
    public MarsWheatherType()
    {
        Field(w => w.MarsSeason);
    }
}

public class SeasonEnum : EnumerationGraphType<Season>
{ }

I've registered it in startup.cs (ConfigureServices method) :

services.AddSingleton<SolDataQuery>();
        services.AddSingleton<SolDataMutation>();
        services.AddSingleton<SeasonEnum>();
        services.AddSingleton<MarsWheatherType>();
        services.AddSingleton<ISchema, SolSchema>();
        

I'm useing GraphQLPlayground. My request is :

wheather {     
 marsSeason}

After all of it I have an error:

GraphQL.Execution.UnhandledError: Error executing document.\r\n ---> >System.InvalidOperationException: Required service for type >GraphQL.Types.EnumerationGraphType`1[Mars.Season] not found\r\n at >GraphQL.Utilities.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type >serviceType) in /_/src/GraphQL/Utilities/ServiceProviderExtensions.cs:line 42

This error has code "INVALID_OPERATION"

Could somebody help me please? What do I do wrong? P.S. If it help, I pushed this not finished project on github

1 Answer 1

2

Ok. The correct code for MarsWheatherType is:

public class MarsWheatherType : ObjectGraphType<MarsWheather>
{
    public MarsWheatherType()
    {
        Field<SeasonEnum>("season", resolve: w => w.Source.MarsSeason);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.