Skip to content

Commit

Permalink
🧪 test out what reading from graphql file to generate file would look…
Browse files Browse the repository at this point in the history
… like
  • Loading branch information
michenly committed Dec 15, 2023
1 parent e1c5d7e commit 1fcf43c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
15 changes: 15 additions & 0 deletions packages/cli/src/lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,20 @@ async function generateDefaultConfig(
const defaultGlob = '*!(*.d).{ts,tsx,js,jsx}'; // No d.ts files
const appDirRelative = relativePath(rootDirectory, appDirectory);

const caapiSchema = getSchema('customer');
const customerAPIProject = findGqlProject(caapiSchema, gqlConfig);

var customerAPIConfig;
if (customerAPIProject?.documents) {
customerAPIConfig = {
['customerapi.generated.d.ts']: {
preset,
schema: caapiSchema,
documents: customerAPIProject?.documents,
},
};
}

return {
filepath: 'virtual:codegen',
config: {
Expand Down Expand Up @@ -228,6 +242,7 @@ async function generateDefaultConfig(
},
}),
},
...customerAPIConfig,
},
},
};
Expand Down
11 changes: 8 additions & 3 deletions templates/skeleton/.graphqlrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ projects:
default:
schema: 'node_modules/@shopify/hydrogen/storefront.schema.json'
documents:
- '!*.d.ts'
- '*.{ts,tsx,js,jsx}'
- 'app/**/*.{ts,tsx,js,jsx}'
- '!*.d.ts'
- '*.{ts,tsx,js,jsx}'
- '!app/graphql/**/*.{ts,tsx,js,jsx}'
- 'app/**/*.{ts,tsx,js,jsx}'
customer:
schema: 'node_modules/@shopify/hydrogen/customer.schema.json'
documents:
- 'app/graphql/customer/**/*.{ts,tsx,js,jsx}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://shopify.dev/docs/api/customer/latest/queries/customer
export const CUSTOMER_DETAILS_QUERY = `#graphql
query CustomerDetails {
customer {
firstName
lastName
}
}
` as const;
21 changes: 21 additions & 0 deletions templates/skeleton/customerapi.generated.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable eslint-comments/no-unlimited-disable */
/* eslint-disable */
import * as CustomerAccountAPI from '@shopify/hydrogen/customer-account-api-types';

export type CustomerDetailsQueryVariables = CustomerAccountAPI.Exact<{ [key: string]: never; }>;


export type CustomerDetailsQuery = { customer: Pick<CustomerAccountAPI.Customer, 'firstName' | 'lastName'> };

interface GeneratedQueryTypes {
"#graphql\n query CustomerDetails {\n customer {\n firstName\n lastName\n }\n }\n": {return: CustomerDetailsQuery, variables: CustomerDetailsQueryVariables},
}

interface GeneratedMutationTypes {
}

declare module '@shopify/hydrogen' {
interface CustomerAccountQueries extends GeneratedQueryTypes {}
interface CustomerAccountMutations extends GeneratedMutationTypes {}
}

0 comments on commit 1fcf43c

Please sign in to comment.