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

Error generating classes for mutation that returns a union #570

Open
humphrey opened this issue Jan 22, 2024 · 4 comments
Open

Error generating classes for mutation that returns a union #570

humphrey opened this issue Jan 22, 2024 · 4 comments

Comments

@humphrey
Copy link

Does Ferry support mutations that return Union types such as the example snippet below?

union UpdatePrefsResponse = MyPrefs | FieldErrors | SimpleMutationError

type Mutation {
  updatePrefs(data: UpdatePrefsInput!): UpdatePrefsResponse!
}

Whenever I try to generate classes for a mutation that returns a union such as this (my graph is full of them) I get the following error:

Exception: UpdatePrefsResponse is not an ObjectTypeDefinitionNode or InterfaceTypeDefinitionNode

Or is there something else going on? My apologies if this is a noob question - this is my first attempt to use ferry for a project (I'm attempting to port my existing graphql_codegen project to ferry)

@knaeckeKami
Copy link
Collaborator

Hi!

Can you share the mutation that leads to that error?

@humphrey
Copy link
Author

Hi!

Can you share the mutation that leads to that error?

Sure thing! Here is the mutation.

mutation UpdatePrefs($data: UpdatePrefsInput!) {
  updatePrefs(data: $data) { 
    ...MyPrefs
    ... on InputError { message }
    ... on FieldError {
      message
      fieldErrors { field, messages }
    }
  }
}

fragment MyPrefs on MyPrefs { dateFormat, firstDayOfWeek }

And here is a full cut down schema needed to reproduce. FYI, this is a simple reproducable adaption from my real schema and mutation (I've deleted most of my code and renamed a number of things for this example). I copied this to a new project with just a schema.graphql and a .graphql file for my mutation, and I get the same error.

union UpdatePrefsResponse = MyPrefs | FieldErrors | SimpleMutationError

type Mutation {
  updatePrefs(data: UpdatePrefsInput!): UpdatePrefsResponse!
}

input UpdatePrefsInput {
  dateFormat: String!
  firstDayOfWeek: Int!
}

type MyPrefs {
  dateFormat: String!
  firstDayOfWeek: Int!
}

interface InputError {
  message: String!
}

type FieldErrors implements InputError {
  message: String!
  fieldErrors: [FieldErrorsField!]!
}

type FieldErrorsField {
  field: String!
  messages: [String!]!
}

type SimpleMutationError implements InputError {
  message: String!
}

@knaeckeKami
Copy link
Collaborator

Thanks!

This might be an issue with fragments spreads on a specific case of a union. will take a look

@comk
Copy link

comk commented Jul 12, 2024

I have the same problem, too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants