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

Complains about null for non-null type #62

Open
rburgst opened this issue Apr 6, 2022 · 1 comment
Open

Complains about null for non-null type #62

rburgst opened this issue Apr 6, 2022 · 1 comment

Comments

@rburgst
Copy link

rburgst commented Apr 6, 2022

I am getting the following error message:

Cannot return null for non-nullable field CMCategory.nameDe.

However, none of the returned CMCategory from the origin graphql server returns null for this field.

A reproduction sample is available at
https://github.com/rburgst/gatsby-graphql-toolkit-bug

This is the server schema

  type Query {
    getCategories: [Category]!
    getConcerts: [Concert]!
  }

  type Category {
    id: String!
    nameDe: String!
    nameEn: String!
    displayOrder: Int!
    isSubcategoryOf: Category
  }
  type Concert {
    id: ID!
    category: Category
    secondCategory: Category
    titleDe: String!
    titleEn: String!
  }

To replicate do the following

  1. start the dev server
    cd server
    pnpm install
    pnpm dev
    
  2. In another shell start a gatsby build
    cd gatsby
    yarn install
    yarn build
    

Expected

the build runs through

Actual

The following error is thrown


 ERROR #85925  GRAPHQL

There was an error in your GraphQL query:

Cannot return null for non-nullable field CMCategory.nameDe.

The field "CMCategory.nameDe." was explicitly defined as non-nullable via the schema customization API (by yourself or a plugin/theme). This means that this field is not optional and you have to define a value. If this is not your
desired behavior and you defined the schema yourself, go to "createTypes" in gatsby-node.js. If you're using a plugin/theme, you can learn more here on how to fix field types:
https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization#fixing-field-types

   1 | fragment ConcertCategoryFragment on CMCategory {
   2 |   remoteId
>  3 |   nameDe
     |   ^
   4 |   nameEn
   5 |   isSubcategoryOf {
   6 |     remoteId
   7 |     nameDe
   8 |     nameEn
   9 |   }
  10 | }
  11 |
@rburgst
Copy link
Author

rburgst commented Apr 6, 2022

Note that when I run the following graphql query in the gatsby graphiql

query MyQuery {
  allCmConcert {
    nodes {
      id
      titleDe
      titleEn
      category {
        remoteId
        nameDe
        isSubcategoryOf {
          remoteId
          nameDe
        }
      }
    }
  }
}

I get the 2nd concert with a null link:

       [ 
       {...},
        {
          "id": "Concert:69e2025a-2573-4d25-b2e1-a6d34a7bcefd",
          "titleDe": "fgdg",
          "titleEn": "asdf",
=>           "category": null
        }
      ]
    }

Even though the source server returns a valid category id.

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