Issue with Nullable Types in Hasura GraphQL Schema Generation

Issue with Nullable Types in Hasura GraphQL Schema Generation


0

I am facing an issue with the return types of Hasura queries when generating schemas using the codegen library (via yarn graphql-codegen –config codegen.ts command). Previously, the generated schema used to look like this:
schema in graphql.schema.json —

{
        "kind": "OBJECT",
        "name": "table_name",
        "description": "columns and relationships of "table_name"",
        "fields": [
    .....
    { 
            "name": "related_table", 
            "description": "An object relationship", 
            "args": [], 
            "type": { 
              "kind": "NON_NULL", 
              "name": null, 
              "ofType": { 
                "kind": "OBJECT", 
                "name": "related_table", 
                "ofType": null 
              } 
            },
    },
    .....
    }

types generated in graphql.tsx —

table_name: {
      col1: number | null;
      col2: string | null;
      col3: string | null;
      related_table: { col1: string; col2: string };
    };

After making changes to the database schema, we now see an unexpected | null condition in some relationships:
schema in graphql.schema.json —

{
        "kind": "OBJECT",
        "name": "table_name",
        "description": "columns and relationships of "table_name"",
        "fields": [
    .....
    { 
            "name": "related_table", 
            "description": "An object relationship", 
            "args": [], 
            "type": { 
              "kind": "OBJECT", 
              "name": "related_table", 
              "ofType": null 
            },
    },
    .....
    }

types generated in graphql.tsx —

table_name: {
      col1: number | null;
      col2: string | null;
      col3: string | null;
      related_table: { col1: string; col2: string } | null;
    };

Can anyone shed light on why the generated types have "| null" condition in the graphql.tsx file generated. We have thoroughly checked foreign keys and constraints, and everything seems to be in order.

Steps Taken:

  • Verified foreign keys and constraints.
  • Checked codegen library configuration.
  • Ensured compatibility with Hasura version.
  • Reviewed Hasura relationship configurations.

Your insights and assistance are greatly appreciated.


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *