Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace DataFetcher registrations to match custom root operation type names #708

Closed
markxj opened this issue May 19, 2023 · 1 comment
Closed
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@markxj
Copy link

markxj commented May 19, 2023

GraphQL (https://spec.graphql.org/October2021/#sec-Schema) allows for the Query and Mutation elements to be renamed as in

schema {
  query: MyQuery
  mutation: MyMutation
}
type MyQuery {
  hello: String!
}
type MyMutation {
  saveGreeting(greeting: String!): String!
}

With a controller

@Controller
public class HelloController {
   private String greeting = "Hello";
   
   @QueryMapping
   public String hello() {
      return greeting;
   }
   
   @MutationMapping
   public String saveGreeting(@Argument String greeting) {
     this.greeting = greeting;
   }
}       

When sending a request, neither method is invoked and the framework silently returns null - with an error of some form

{
  "errors": [
    {
      "message": "The field at path '/hello' was declared as a non null type, but the code involved in retrieving data has wrongly returned a null value.  The graphql specification requires that the parent field be set to null, or if that is non nullable that it bubble up null to its parent and so on. The non-nullable type is 'String' within parent type 'MyQuery'",
      "path": [
        "hello"
      ],
      "extensions": {
        "classification": "NullValueInNonNullableField"
      }
    }
  ],
  "data": null
}

I also tried changing my annotations @QueryMapping("MyQuery.hello") but that doesn't work either.

Does the framework only support Query and Mutation for the names? That makes it difficult to bring in 3rd party schemas

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 19, 2023
@rstoyanchev
Copy link
Contributor

rstoyanchev commented May 21, 2023

Thanks for bringing up this question.

Currently @QueryMapping is just a shortcut for @SchemaMapping(typeName="Query"), and as a RuntimeWiringConfigurer the AnnotatedControllerConfigurer does not have access to schema types. We would need to provide it with a TypeDefinitionRegistry where it can look up the names for Query and Mutation types.

I'll schedule this to give it a try. In the mean, you could create your own @MyQueryMapping meta annotation, following the example of @QueryMapping.

@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 21, 2023
@rstoyanchev rstoyanchev self-assigned this May 21, 2023
@rstoyanchev rstoyanchev added this to the 1.3 Backlog milestone May 21, 2023
@rstoyanchev rstoyanchev changed the title Does not support renamed Query/Mutation in the schema element Support custom type names for query, mutation, and subscription operations May 21, 2023
@rstoyanchev rstoyanchev modified the milestones: 1.3 Backlog, 1.3.0-RC1 Apr 11, 2024
@rstoyanchev rstoyanchev changed the title Support custom type names for query, mutation, and subscription operations Replace DataFetcher registrations to match custom root operation type names Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants