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

Incorrect Schema When Using Mutation Conventions #4576

Closed
1 task done
nollidnosnhoj opened this issue Dec 17, 2021 · 1 comment · Fixed by #4577
Closed
1 task done

Incorrect Schema When Using Mutation Conventions #4576

nollidnosnhoj opened this issue Dec 17, 2021 · 1 comment · Fixed by #4577
Labels
Area: Type System Issue is related to the Type System 🐛 bug Something isn't working 🌶️ hot chocolate

Comments

@nollidnosnhoj
Copy link

nollidnosnhoj commented Dec 17, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using mutation conventions and explicitly defining the type and field name for payload, it produces the incorrect schema.

According to the documentation, the PayloadFieldName is the name of the field in the payload that represents the data....

type Mutation {
  createUser(input: CreateUserCustomInput): CreateUserPayload
}

type CreateUserPayload {
   thisIsTheFieldName: User
   errors: [CreateUserError!]
}

... and PayloadTypeName is the type name of the payload.

type Mutation {
  createUser(input: CreateUserCustomInput): ThisIsTheTypeName
}

Here is the C# code.

[UseMutationConvention(
        InputArgumentName = "input", 
        InputTypeName = "HelloWorldInput", 
        PayloadFieldName = "message", 
        PayloadTypeName = "HelloWorldPayload"
)]
public string HelloWorldAsync(string name)
{
    return $"Hello, {name}!";
}

Expected schema:

type Mutation {
  helloWorldAsync(input: HelloWorldInput!): HelloWorldPayload!
}

input HelloWorldInput {
  name: String!
}

type HelloWorldPayload {
  message: String
}

Actual schema:

type Mutation {
  helloWorldAsync(input: HelloWorldInput!): message!
}

input HelloWorldInput {
  name: String!
}

type message {
  HelloWorldPayload: String
}

In the actual schema, the field and type name are switched.

One thing to note, I've tried this without explicitly defining type and field names (no arguments in mutation convention attribute), and the schema got the payload type correct (based on convention), but the payload field name is string, (which I assume is working as intended since I am only returning a string, not an object.)

Please let me know if I need more information. I am happy to provide more! And lastly, I am new to GraphQL so I may be getting things wrong. If so, let me know!

Thanks!

Steps to reproduce

  1. Create a mutation that uses the mutation convention.
  2. Ensure that the mutation method returns a string, or any type that isn't an object.
  3. In the convention, explicitly define the Payload field and type name.

Relevant log output

No response

Additional Context?

No response

Product

Hot Chocolate

Version

12.4.0

@nollidnosnhoj nollidnosnhoj added the 🐛 bug Something isn't working label Dec 17, 2021
@tobias-tengler tobias-tengler added Area: Type System Issue is related to the Type System 🌶️ hot chocolate labels Dec 17, 2021
@PascalSenn
Copy link
Member

@nollidnosnhoj Ooops, refactoring bug! Thanks for reporting!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Type System Issue is related to the Type System 🐛 bug Something isn't working 🌶️ hot chocolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants