I want to edit Hydrogen's codegen.ts to fetch the Admin API schema. #2275
-
Hello, codegen.ts import type {CodegenConfig} from '@graphql-codegen/cli';
import {pluckConfig, preset, getSchema} from '@shopify/hydrogen-codegen';
import {preset as adminApiPreset} from '@shopify/api-codegen-preset';
export default {
overwrite: true,
pluckConfig,
generates: {
'storefrontapi.generated.d.ts': {
preset,
schema: getSchema('storefront'),
documents: [
'./*.{ts,tsx,js,jsx}',
'./app/**/*.{ts,tsx,js,jsx}',
'!./app/graphql/customer-account/*.{ts,tsx,js,jsx}',
],
},
'customer-accountapi.generated.d.ts': {
preset,
schema: getSchema('customer-account'),
documents: ['./app/graphql/customer-account/*.{ts,tsx,js,jsx}'],
},
'adminapi.generated.d.ts': {
preset: adminApiPreset,
plugins: ['typescript'],
schema: 'https://shopify.dev/admin-graphql-direct-proxy',
},
},
} as CodegenConfig; When I run
Please help me 😭 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You could get some inspiration from #1011 But also remember to add a You'll also want to make sure that you're passing a version to the Admin API URL like this: https://shopify.dev/docs/api/shopify-app-remix/v2/guide-graphql-types#configure |
Beta Was this translation helpful? Give feedback.
-
I think this would be the simplest: // <root>/codegen.ts
import type {CodegenConfig} from '@graphql-codegen/cli';
import {pluckConfig, preset, getSchema} from '@shopify/hydrogen-codegen';
import {ApiType, shopifyApiTypes} from '@shopify/api-codegen-preset';
export default {
overwrite: true,
pluckConfig,
generates: {
'storefrontapi.generated.d.ts': {
preset,
schema: getSchema('storefront'),
documents: [
'./*.{ts,tsx,js,jsx}',
'./app/**/*.{ts,tsx,js,jsx}',
'!./app/graphql/**/*.{ts,tsx,js,jsx}',
],
},
'customer-accountapi.generated.d.ts': {
preset,
schema: getSchema('customer-account'),
documents: ['./app/graphql/customer-account/*.{ts,tsx,js,jsx}'],
},
...shopifyApiTypes({
apiType: ApiType.Admin,
apiVersion: '2024-07',
documents: ['./app/graphql/admin/*.{js,ts,jsx,tsx}']
}),
},
} as CodegenConfig; Otherwise, you can also do what |
Beta Was this translation helpful? Give feedback.
I was able to get it working by running
graphql-codegen
directly instead of going through Hydrogen's CLI command. One tweak you'll want to make:I then ran
npx graphql-codegen --config .graphqlrc.ts
and successfully generated the types.