Skip to content

Misc. type related errors #188

Open
Open
@creimers

Description

@creimers

I'm using this library to generate mocks of a hasura graphql api.

With these versions installed

"@graphql-codegen/cli": "^5.0.7"
"@graphql-codegen/client-preset": "^4.8.3"
"graphql-codegen-typescript-mock-data": "^5.0.0"

and this configuration

import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  overwrite: true,
  schema:  "http://localhost:8080/v1/graphql",
  documents: "./**/*.{tsx,ts}",
  generates: {
    "lib/gql/generated/": {
      preset: "client",
      presetConfig: {
        fragmentMasking: { unmaskFunctionName: "getFragmentData" },
      },
    },
    "lib/gql/mocks/": {
      preset: "client",
      plugins: [
        {
          "typescript-mock-data": {
            terminateCircularRelationships: true,
            addTypename: true,
          },
        },
      ],
    },
  },
};

export default config;

I'm running into quite some type related errors in lib/gql/mocks/graphql.ts.

For example, this block

export const aBooleanComparisonExp = (overrides?: Partial<BooleanComparisonExp>, _relationshipsToOmit: Set<string> = new Set()): BooleanComparisonExp => {
    const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit);
    relationshipsToOmit.add('BooleanComparisonExp');
    return {
        _eq: overrides && overrides.hasOwnProperty('_eq') ? overrides._eq! : false,
        _gt: overrides && overrides.hasOwnProperty('_gt') ? overrides._gt! : false,
        _gte: overrides && overrides.hasOwnProperty('_gte') ? overrides._gte! : true,
        _in: overrides && overrides.hasOwnProperty('_in') ? overrides._in! : [false],
        _is_null: overrides && overrides.hasOwnProperty('_is_null') ? overrides._is_null! : true,
        _lt: overrides && overrides.hasOwnProperty('_lt') ? overrides._lt! : true,
        _lte: overrides && overrides.hasOwnProperty('_lte') ? overrides._lte! : true,
        _neq: overrides && overrides.hasOwnProperty('_neq') ? overrides._neq! : false,
        _nin: overrides && overrides.hasOwnProperty('_nin') ? overrides._nin! : [true],
    };
};

yields the following typescript error:

Cannot find name BooleanComparisonExp . Did you mean Boolean_Comparison_Exp ?

There's a lot more following the same pattern, e.g. FloatComparisonExp, StringComparisonExp, etc.

But then there's also cases like this

export const anApiKeyAvgOrderBy = (overrides?: Partial<ApiKeyAvgOrderBy>, _relationshipsToOmit: Set<string> = new Set()): ApiKeyAvgOrderBy => {
    const relationshipsToOmit: Set<string> = new Set(_relationshipsToOmit);
    relationshipsToOmit.add('ApiKeyAvgOrderBy');
    return {
        id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : OrderBy.Asc,
        organisation_id: overrides && overrides.hasOwnProperty('organisation_id') ? overrides.organisation_id! : OrderBy.Asc,
    };
};

where the typescript error is just

Cannot find name ApiKeyBoolExp or Cannot find name OrderBy.

To me it looks like I must have gotten some part of the configuration wrong, but I'm struggling to understand which setting to set to what value in order to resolve these typescript errors.

Can you help me find the error? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions