2

For background, I am following the tutorial here: https://www.youtube.com/watch?v=HuN94qNwQmM .

As the code is too long I am putting that in git https://github.com/dikeshkumar135/CommandERGQL

Now, coming to the problem, when I am making request with this body

    query{
     platform{
       id,
       name,
       commands{
         howTo
       }
     }
    }

I am getting the data for platform with commands value as null and the below error:

{
  "message": "There was no argument with the name `platform` found on the field `commands`.",
  "locations": [
    {
      "line": 5,
      "column": 5
    }
  ],
  "path": [
    "platform",
    1,
    "commands"
  ],
  "extensions": {
    "fieldName": "commands",
    "argumentName": "platform"
  }

If I remove the type it's working fine, but if I add type then the problem occurs to get related objects.

4 Answers 4

7

In HotChocolate v12, DependecyInjection included in the ResolverWith method assumes all parameters as an Argument. Except for below

There are also specific arguments that will be automatically populated by Hot Chocolate when the resolver is executed. These include Dependency injection services, DataLoaders, state, or even context like a parent value.

Documentation Source

Here is some example for the upgrade for the tutorial you are using

public IQueryable<Command> GetCommands(
    [Parent] Platform platform,
    [ScopedService] AppDbContext context)
{
    return context.Commands.Where(p => p.PlatformId == platform.Id);
}
Sign up to request clarification or add additional context in comments.

Comments

1

I downgraded hotchocolate packages from 12.0.1 to 11.0.8 ad it worked. It was a suggestion to my comment in youtube.

Comments

1

if you don't have goal to update data, you can omit to use EF and use, just for exmaple, NReco.GraphQL to set up graphql schema (including relation between schema objects) via json-style definition. Setting db-connection quite easy and under the hood it's ORM.

Comments

0

Here is my Type class

 public class MajorType : ObjectType<Major>
    {
        protected override void Configure(IObjectTypeDescriptor<Major> descriptor)
        {
            descriptor.Description("Offer Degree from the university");
            descriptor.Field(p => p.MinCreditHours).Description("Minimum credit hours for the degree");
            descriptor.Field(p => p.SetUser).Ignore();
            descriptor.Field(p => p.SetDate).Ignore();
            descriptor.Field(p => p.IsDeleted).Ignore();
          
            descriptor.Field(p=>p.Courses)
                .UseDbContext<CatalogueDBContext>()
                .ResolveWith<Resolvers>(p=>p.GetCourse(default!,default!))
                .Description("Avialable coures for the specific major");
        }
        private class Resolvers 
        {
            public IQueryable<Courses> GetCourse([Parent] Major major, [ScopedService] CatalogueDBContext context)
            {
                return context.Courses.Where(c=>c.MajorId == major.Id);
            }
        }
    }

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.