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

[with graphql-codegen] Using optional argument, but required to pass argument #10

Open
mackeee-orange opened this issue Jul 26, 2021 · 0 comments

Comments

@mackeee-orange
Copy link

Hi @Quramy .
I love this library. This is very useful.

I am using it with graphql-codegen.

define fragment

export const KCG_CARD_FRAGMENT = gql`
  fragment KCGCardKnowledgeCategoryGroup on KnowledgeCategoryGroup
  @argumentDefinitions(
    level: { type: "EngineerLevel", defaultValue: NEWBIE }
    occupation: { type: "EngineerOccupation", defaultValue: BACKEND }
  ) {
    id
    name
    programmingResource {
      id
      name
      thumbnailUrl
    }
    knowledgeCategories(level: $level, occupation: $occupation) {
      edges {
        node {

and using the fragment like this

export const CREATE_KCG_MUTATION = gql`
  mutation CreateKnowledgeCategoryGroup($name: String!, $programmingResourceId: ID) {
    createKnowledgeCategoryGroup(
      input: { name: $name, programmingResourceId: $programmingResourceId }
    ) {
      knowledgeCategoryGroup {
        ...KCGCardKnowledgeCategoryGroup
      }
    }
  }

  ${KCG_CARD_FRAGMENT}
`;

Where, those arguments level and occupation are optional.
But graphql-codegen says

AggregateError: 
        GraphQLDocumentError: Variable "$level" is not defined by operation "CreateKnowledgeCategoryGroup".

Does it bug??
If it is my fault, please teach me correct definition.

version info

node is v14.15.4

    "graphql": "14.7.0",
    "@graphql-codegen/add": "2.0.1",
    "@graphql-codegen/cli": "1.16.3",
    "@graphql-codegen/typescript": "1.16.3",
    "@graphql-codegen/typescript-operations": "1.16.3",
    "@graphql-codegen/typescript-react-apollo": "1.16.3",
    "@graphql-codegen/fragment-matcher": "1.17.8",
    "apollo-link-fragment-argument": "1.0.1",
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

1 participant