graphql-code-generator: Error when fragments are separated

Currently when fragments are stored separately from queries and mutations, the codegen produces a “Unknown fragment …” error.

Example:

fragment.ts

import gql from 'graphql-tag';

export const userInfo = gql`
  fragment UserInfo on User {
    id
    name
    email
  }
`;

query.ts

import gql from 'graphql-tag';

import { userInfo } from './fragment.ts';

export const userQuery = gql`
  query UserQuery($id: ID!) {
    user(id: $id) {
      ...UserInfo
    }
  }

  ${userInfo}
`;

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 15 (3 by maintainers)

Most upvoted comments

@LawJolla In 1.0.7 we fixed that, now you’ll get a more readable error with the missing fragment name. If you are still having issues, please open a new issue because this one is closed and outdated.