-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add our scalars to the package for other developers (#69)
* Add our scalars to the package for other developers * Update .changeset/swift-olives-beam.md Co-authored-by: Ren Chaturvedi <[email protected]> * Update .changeset/swift-olives-beam.md Co-authored-by: Ren Chaturvedi <[email protected]> * Update apps/nextjs/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update apps/nextjs/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update apps/nextjs/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/README.md Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/README.md Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/codegen.ts Co-authored-by: Ren Chaturvedi <[email protected]> * Update packages/react/src/codegen.helpers.ts Co-authored-by: Ren Chaturvedi <[email protected]> Co-authored-by: Ren Chaturvedi <[email protected]>
- Loading branch information
Showing
11 changed files
with
143 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
'@shopify/hydrogen-react': patch | ||
--- | ||
|
||
Provide a mapping of Storefront API's custom scalars to their actual types, for use with GraphQL CodeGen. | ||
|
||
For example: | ||
|
||
```ts | ||
import {storefrontApiCustomScalars} from '@shopify/hydrogen-react'; | ||
|
||
const config: CodegenConfig = { | ||
// Use the schema that's bundled with @shopify/hydrogen-react | ||
schema: './node_modules/@shopify/hydrogen-react/storefront.schema.json', | ||
generates: { | ||
'./gql/': { | ||
preset: 'client', | ||
plugins: [], | ||
config: { | ||
// Use the custom scalar definitions that @shopify/hydrogen-react provides to improve the custom scalar types | ||
scalars: storefrontApiCustomScalars, | ||
}, | ||
}, | ||
}, | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import {CodegenConfig} from '@graphql-codegen/cli'; | ||
// Because this file is processed only in TypeScript, we can make one exception for not using an extension here. | ||
// eslint-disable-next-line import/extensions | ||
import {storefrontApiCustomScalars} from './src/codegen.helpers'; | ||
|
||
const config: CodegenConfig = { | ||
overwrite: true, | ||
schema: { | ||
'https://hydrogen-preview.myshopify.com/api/2022-10/graphql.json': { | ||
headers: { | ||
'X-Shopify-Storefront-Access-Token': '3b580e70970c4528da70c98e097c2fa0', | ||
'content-type': 'application/json', | ||
}, | ||
}, | ||
}, | ||
generates: { | ||
// The generated base types | ||
'src/storefront-api-types.d.ts': { | ||
plugins: [ | ||
{ | ||
add: { | ||
content: ` | ||
/** | ||
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT | ||
* Based on Storefront API 2022-10 | ||
* If changes need to happen to the types defined in this file, then generally the Storefront API needs to update. After it's updated, you can run \`yarn graphql-types\`. | ||
* Except custom Scalars, which are defined in the \`codegen.ts\` file | ||
*/ | ||
/* eslint-disable */`, | ||
}, | ||
}, | ||
{ | ||
typescript: { | ||
useTypeImports: true, | ||
// If a default type for a scalar isn't set, then instead of 'any' we set to 'unknown' for better type safety. | ||
defaultScalarType: 'unknown', | ||
useImplementingTypes: true, | ||
enumsAsTypes: true, | ||
// Define how the Storefront API's custom scalars map to TypeScript types | ||
scalars: storefrontApiCustomScalars, | ||
}, | ||
}, | ||
], | ||
}, | ||
// The schema file, which is the local representation of the GraphQL endpoint | ||
'./storefront.schema.json': { | ||
plugins: [ | ||
{ | ||
introspection: { | ||
minify: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** Meant to be used with GraphQL CodeGen to type the Storefront API's custom scalars correctly */ | ||
export const storefrontApiCustomScalars = { | ||
// Keep in sync with the definitions in the app/nextjs/codegen.ts! | ||
DateTime: 'string', | ||
Decimal: 'string', | ||
HTML: 'string', | ||
URL: 'string', | ||
Color: 'string', | ||
UnsignedInt64: 'string', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters