Shopify / shopify-app-js

MIT License
284 stars 112 forks source link

@shopify/api-codegen-preset 1.0.1: introspectionResult.errors.map is not a function / #1128

Closed florianbepunkt closed 3 months ago

florianbepunkt commented 4 months ago

Issue summary

Before opening this issue, I have:

Using the @shopify/api-codegen-preset throws an error during type generation: introspectionResult.errors.map is not a function. This might be caused by https://shopify.dev/admin-graphql-direct-proxy/2023-10 (from the docs config) returning a 404.

Expected behavior

I should be able to reproduce the example from the docs: https://shopify.dev/docs/api/shopify-app-remix/v3/guide-graphql-types

Actual behavior

What actually happens?

✔ Parse Configuration
⚠ Generate outputs
  ❯ Generate to ./src/types/admin-2023-10.schema.json
    ✖ introspectionResult.errors.map is not a function
    ◼ Load GraphQL documents
    ◼ Generate

Steps to reproduce the problem

Follow the docs https://shopify.dev/docs/api/shopify-app-remix/v3/guide-graphql-types

storz commented 4 months ago

I'm encountering the same issue.

This might be caused by https://shopify.dev/admin-graphql-direct-proxy/2023-10 (from the docs config) returning a 404.

The endpoint likely exists and returns a non-404 response to a POST request (although this doesn't provide information to solve the problem)

$ curl -X POST https://shopify.dev/admin-graphql-direct-proxy/2023-10
{"errors":{"query":"Required parameter missing or invalid"}}%

Additionally, the same situation occurs when changing the version to 2024-01, 2024-04, or 2024-07 (release candidate).

chenaski commented 4 months ago

I can confirm the same error. I wasn't able to identify the exact reason, but it probably happened after packages update.

The current workaround I found is to use your shop's API directly: https://${STORE_DOMAIN}/admin/api/${API_VERSION}/graphql.json instead of using https://shopify.dev/admin-graphql-direct-proxy.

Here's the full version of our `codegen.ts` file, might be useful for someone ```typescript import type {CodegenConfig} from '@graphql-codegen/cli'; import {getSchema, pluckConfig, preset} from '@shopify/hydrogen-codegen'; import {ApiType} from '@shopify/api-codegen-preset'; const outputDir = './app/generated'; const queriesDir = './app/graphql'; const STORE_DOMAIN = ''; const ACCESS_TOKEN = ''; const API_VERSION = '2024-04'; const adminSchema: CodegenConfig['schema'] = { [`https://${STORE_DOMAIN}/admin/api/${API_VERSION}/graphql.json`]: { headers: {'X-Shopify-Access-Token': ACCESS_TOKEN}, }, }; const storefrontDocuments = ['./app/**/*.{ts,tsx}', `!${outputDir}`, `!${queriesDir}/**`]; const customerAccountDocuments = `${queriesDir}/customer-account/*.ts`; const adminDocuments = [`${queriesDir}/admin-api/*.ts`]; const migrationDocuments = './migrations/**/*.ts'; export default { overwrite: true, pluckConfig: pluckConfig as CodegenConfig['pluckConfig'], generates: { [`${outputDir}/storefrontapi.generated.d.ts`]: { preset, schema: getSchema('storefront'), documents: storefrontDocuments, }, [`${outputDir}/customeraccountapi.generated.d.ts`]: { preset, schema: getSchema('customer-account'), documents: customerAccountDocuments, }, [`${outputDir}/admin.schema.json`]: { schema: adminSchema, documents: adminDocuments, plugins: ['introspection'], config: {minify: true}, }, [`${outputDir}/admin.types.d.ts`]: { schema: adminSchema, documents: adminDocuments, plugins: ['typescript'], }, [`${outputDir}/admin.generated.d.ts`]: { schema: adminSchema, documents: adminDocuments, preset, presetConfig: { apiType: ApiType.Admin, apiVersion: '2024-04', }, }, [`${outputDir}/admin.sdk.ts`]: { schema: adminSchema, documents: adminDocuments, preset: 'import-types', presetConfig: { typesPath: './admin.generated', importTypesNamespace: 'Operations', }, plugins: ['typescript-generic-sdk'], config: { importOperationTypesFrom: 'Operations', }, }, [`${outputDir}/migrations.generated.d.ts`]: { schema: adminSchema, documents: migrationDocuments, preset, presetConfig: { apiType: ApiType.Admin, apiVersion: '2024-04', }, }, }, } satisfies CodegenConfig; ```
skelouse commented 4 months ago

https://shopify.dev/admin-graphql-direct-proxy/2024-04 is returning a 200:

{ "errors": "Not Found" }

Here's a curl to get the same error:

curl -X POST 'https://shopify.dev/admin-graphql-direct-proxy/2024-04' \
-H 'Accept: application/graphql-response+json, application/json, multipart/mixed' \
-H 'Content-Type: application/json' \
-d '{"query":"query IntrospectionQuery {\\n  __schema {\\n    queryType {\\n      name\\n    }\\n    mutationType {\\n      name\\n    }\\n    subscriptionType {\\n      name\\n    }\\n    types {\\n      ...FullType\\n    }\\n    directives {\\n      name\\n      description\\n      locations\\n      args {\\n        ...InputValue\\n      }\\n    }\\n  }\\n}\\n\\nfragment FullType on __Type {\\n  kind\\n  name\\n  description\\n  fields(includeDeprecated: true) {\\n    name\\n    description\\n    args {\\n      ...InputValue\\n    }\\n    type {\\n      ...TypeRef\\n    }\\n    isDeprecated\\n    deprecationReason\\n  }\\n  inputFields {\\n    ...InputValue\\n  }\\n  interfaces {\\n    ...TypeRef\\n  }\\n  enumValues(includeDeprecated: true) {\\n    name\\n    description\\n    isDeprecated\\n    deprecationReason\\n  }\\n  possibleTypes {\\n    ...TypeRef\\n  }\\n}\\n\\nfragment InputValue on __InputValue {\\n  name\\n  description\\n  type {\\n    ...TypeRef\\n  }\\n  defaultValue\\n}\\n\\nfragment TypeRef on __Type {\\n  kind\\n  name\\n  ofType {\\n    kind\\n    name\\n    ofType {\\n      kind\\n      name\\n      ofType {\\n        kind\\n        name\\n        ofType {\\n          kind\\n          name\\n          ofType {\\n            kind\\n            name\\n            ofType {\\n              kind\\n              name\\n              ofType {\\n                kind\\n                name\\n                ofType {\\n                  kind\\n                  name\\n                  ofType {\\n                    kind\\n                    name\\n                  }\\n                }\\n              }\\n            }\\n          }\\n        }\\n      }\\n    }\\n  }\\n}"}'
anhdd-kuro commented 4 months ago

Same here ! I think this's kind of critical and need fix asap

suryarajendhran commented 4 months ago

Facing the same issue with the remix app example.

slootjes commented 4 months ago

Facing this issue too, please fix this Shopify.

junyuanxue commented 4 months ago

Same here, would appreciate some 👀 and 🔧 from Shopify! 🙏

nathanerwin commented 4 months ago

Getting same issue since Friday! Definitely needs to be addressed ASAP!

mkromann commented 4 months ago

Same issue here.

Tandashi commented 4 months ago

Switching from @shopify/api-codegen-preset to @shopify/hydrogen-codegen as well as codegen.ts instead of .graphqlrc works for us now.

The minimal configuration we are using right now:

import { type CodegenConfig } from '@graphql-codegen/cli';
import { getSchema, pluckConfig, preset } from '@shopify/hydrogen-codegen';

const documents = ['./src/**/*.{ts,tsx}', '!node_modules'];
const outputDir = './src/client/shopify/gen';

const config: CodegenConfig = {
  overwrite: true,
  pluckConfig: pluckConfig as CodegenConfig['pluckConfig'],
  generates: {
    [`${outputDir}/storefront.generated.d.ts`]: {
      preset,
      schema: getSchema('storefront'),
      documents,
    },
    [`${outputDir}/storefront.types.d.ts`]: {
      schema: getSchema('storefront'),
      documents,
      plugins: ['typescript'],
    },
  },
};

export default config;
matteodepalo commented 4 months ago

Hi @florianbepunkt, thank you for opening this issue, the team is taking a look now.

xqwtsz commented 4 months ago

same issue here, tried different api versions and also package versions, problem persists.

noahub commented 4 months ago

It looks like this may be resolved now @matteodepalo? I'm now able to generate my types as expected.

nathanerwin commented 4 months ago

This is still open for admin api codegen schema and types

nathanerwin commented 4 months ago

Switching from @shopify/api-codegen-preset to @shopify/hydrogen-codegen as well as codegen.ts instead of .graphqlrc works for us now.

The minimal configuration we are using right now:

import { type CodegenConfig } from '@graphql-codegen/cli';
import { getSchema, pluckConfig, preset } from '@shopify/hydrogen-codegen';

const documents = ['./src/**/*.{ts,tsx}', '!node_modules'];
const outputDir = './src/client/shopify/gen';

const config: CodegenConfig = {
  overwrite: true,
  pluckConfig: pluckConfig as CodegenConfig['pluckConfig'],
  generates: {
    [`${outputDir}/storefront.generated.d.ts`]: {
      preset,
      schema: getSchema('storefront'),
      documents,
    },
    [`${outputDir}/storefront.types.d.ts`]: {
      schema: getSchema('storefront'),
      documents,
      plugins: ['typescript'],
    },
  },
};

export default config;

This wont work for admin api

skelouse commented 4 months ago

Schema endpoints are back online, issue resolved.

matteodepalo commented 3 months ago

Thank you everyone for your patience. As @skelouse pointed our we've resolved the issue. Please feel free to open a new one if you experience problems with api-codegen-preset.