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

Naming issues with custom Query root type #75

Closed
eliasdarruda opened this issue Mar 1, 2023 · 5 comments · Fixed by #77
Closed

Naming issues with custom Query root type #75

eliasdarruda opened this issue Mar 1, 2023 · 5 comments · Fixed by #77
Labels
bug Something isn't working

Comments

@eliasdarruda
Copy link

eliasdarruda commented Mar 1, 2023

I think there is a issue when the __typename doesnt follow the "Query" or "Mutation" pattern

Testing the following query (querying through hasura)

query Schedules {
  schedules {
    id
    start_hour
  }
}

typescript-operations generates for me:

export type SchedulesQuery = {
  __typename?: 'query_root',
  schedules: Array<{ __typename?: 'schedules', id: number, start_hour: string }>
}

What graphql-codegen-factories/operations generates for me is:

export function createSchedulesquery_RootMock(props: Partial<Schedulesquery_Root> = {}): Schedulesquery_Root {
  return {
    __typename: "query_root",
    schedules: [],
    ...props,
  };
}

The expected output here should be:

export function createSchedulesQueryMock(props: Partial<SchedulesQuery> = {}): SchedulesQuery {
  return {
    __typename: "query_root",
    schedules: [],
    ...props,
  };
}

Here is what I'm using for my codegen.ts file:

import { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
  schema: 'http://.....',
  documents: ['src/**/*.ts'],
  ignoreNoDocuments: true, // for better experience with the watcher
  generates: {
    './src/_generated_gql/': {
      preset: 'client',
      plugins: [
        'graphql-codegen-factories/schema',
        'graphql-codegen-factories/operations',
      ],
    },
  },
}

export default config
@zhouzi
Copy link
Owner

zhouzi commented Mar 3, 2023

Thanks for reporting! Could you share the configuration you are using with typescript-operations, please?

@eliasdarruda
Copy link
Author

Thanks for reporting! Could you share the configuration you are using with typescript-operations, please?

Its implicitly included in the client preset

@zhouzi zhouzi changed the title Incorrect use of __typename Naming issues with custom Query root type Mar 6, 2023
@zhouzi
Copy link
Owner

zhouzi commented Mar 6, 2023

I was able to reproduce this issue with:

query CustomQuery {
  ...
}

schema {
  query: CustomQuery
}

I'm looking into it and will let you know once the fix is released 👌

@zhouzi zhouzi added the bug Something isn't working label Mar 6, 2023
@zhouzi zhouzi closed this as completed in #77 Mar 6, 2023
@zhouzi
Copy link
Owner

zhouzi commented Mar 6, 2023

@eliasdarruda this is now fixed as of v1.2.1. Feel free to give it a go and let me know if you're facing any other issues when using it with the client presets and hasura 😉

@eliasdarruda
Copy link
Author

Thanks a lot! it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants