hygraph/gatsby-source-graphcms

GraphQL Error when Querying Model that Has a Union Multiple Type Prop

phil-lgr opened this issue · 5 comments

I have an error with the lastest beta version .8

This query works with the GraphCMS.com playground:

{
  forms {
    id
    name
    formFields {
      __typename
      ... on FormField {
        id
        name
        locale
      }
      ... on FormFieldGroup {
        id
        locale
      }
    }
  }
}

but locally it doesn't:

query MyQuery {
  allGraphCmsForm {
    nodes {
      id
      name
      formFields {
        ... on GraphCMS_FormField {
          id
          name
        }
      }
    }
  }
}

Here is the error we get:

{
  "errors": [
    {
      "message": "Abstract type GraphCMS_FormFormFields must resolve to an Object type at runtime for field GraphCMS_Form.formFields with value {}, received \"null\". Either the GraphCMS_FormFormFields type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
      "locations": [
        {
          "line": 6,
          "column": 7
        }
      ],
      "path": [
        "allGraphCmsForm",
        "nodes",
        0,
        "formFields",
        1
      ],
      "stack": [
        "GraphQLError: Abstract type GraphCMS_FormFormFields must resolve to an Object type at runtime for field GraphCMS_Form.formFields with value {}, received \"null\". Either the GraphCMS_FormFormFields type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
        "    at ensureValidRuntimeType (/Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:667:11)",
        "    at completeAbstractValue (/Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:660:42)",
        "    at completeValue (/Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:585:12)",
        "    at completeValue (/Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:557:21)",
        "    at completeValueCatchingError (/Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:495:19)",
        "    at /Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:618:25",
        "    at Array.forEach (<anonymous>)",
        "    at forEach (/Users/phil/Documents/Code/newrade/node_modules/iterall/index.js:83:25)",
        "    at completeListValue (/Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:614:24)",
        "    at completeValue (/Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:573:12)",
        "    at completeValue (/Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:557:21)",
        "    at /Users/phil/Documents/Code/newrade/node_modules/graphql/execution/execute.js:492:16",
        "    at processTicksAndRejections (internal/process/task_queues.js:93:5)",
        "    at async Promise.all (index 2)",
        "    at async Promise.all (index 0)",
        "    at async Promise.all (index 0)"
      ]
    }
  ],
  "data": null,
  "extensions": {
    "enableRefresh": "true"
  }
}

cc @elliotpellerin

ynnoj commented

@phil-lgr Can you please share the generated GraphQL fragment for type Form?

Also, some kind of reproduction if possible (Codesandbox, GitHub repo). Will be very useful!

fragment Form on Form {
  stage
  locale
  remoteId: id
  createdAt(variation: COMBINED)
  updatedAt(variation: COMBINED)
  publishedAt(variation: COMBINED)
  remoteParent: parent {
    ... on Form {
      remoteTypeName: __typename
      remoteId: id
      locale
    }
  }
  name
  childs {
    ... on Form {
      remoteTypeName: __typename
      remoteId: id
      locale
    }
  }
  formFields {
    ... on FormField {
      remoteTypeName: __typename
      remoteId: id
      locale
    }
  }
}
fragment FormField on FormField {
  stage
  locale
  remoteId: id
  createdAt(variation: COMBINED)
  updatedAt(variation: COMBINED)
  publishedAt(variation: COMBINED)
  type
  name
  placeholder
  validations {
    ... on FormFieldValidation {
      remoteTypeName: __typename
      remoteId: id
      locale
    }
  }
  form {
    ... on Form {
      remoteTypeName: __typename
      remoteId: id
      locale
    }
  }
}
fragment FormFieldGroup on FormFieldGroup {
  stage
  locale
  remoteId: id
  createdAt(variation: COMBINED)
  updatedAt(variation: COMBINED)
  publishedAt(variation: COMBINED)
  name
  formFields {
    ... on FormField {
      remoteTypeName: __typename
      remoteId: id
      locale
    }
  }
  form {
    ... on Form {
      remoteTypeName: __typename
      remoteId: id
      locale
    }
  }
}

One thing I don't get is formFields

formFields {
    ... on FormField {
      remoteTypeName: __typename
      remoteId: id
      locale
    }
  }

Can be linked to FormField or FormFieldGroup

Do you see anything wrong with the schemas?

Ok somehow we regenerated it again with the new version and it seems fine! Closing for now

Thanks @ynnoj