-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): create graphql schema using gql.tada (#658)
- Loading branch information
1 parent
dc752bf
commit 8ff2eb6
Showing
7 changed files
with
83 additions
and
67 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,6 @@ | ||
--- | ||
"@bigcommerce/create-catalyst": minor | ||
"@bigcommerce/catalyst-core": minor | ||
--- | ||
|
||
create graphql schema using gql.tada |
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,52 @@ | ||
const { generateSchema, generateTadaTypes } = require('@gql.tada/cli-utils'); | ||
|
||
const graphqlApiDomain = process.env.BIGCOMMERCE_GRAPHQL_API_DOMAIN ?? 'mybigcommerce.com'; | ||
|
||
const getStoreHash = () => { | ||
const storeHash = process.env.BIGCOMMERCE_STORE_HASH; | ||
|
||
if (!storeHash) { | ||
throw new Error('Missing store hash'); | ||
} | ||
|
||
return storeHash; | ||
}; | ||
|
||
const getChannelId = () => { | ||
const channelId = process.env.BIGCOMMERCE_CHANNEL_ID; | ||
|
||
return channelId; | ||
}; | ||
|
||
const getToken = () => { | ||
const token = process.env.BIGCOMMERCE_CUSTOMER_IMPERSONATION_TOKEN; | ||
|
||
if (!token) { | ||
throw new Error('Missing customer impersonation token'); | ||
} | ||
|
||
return token; | ||
}; | ||
|
||
const getEndpoint = () => { | ||
const storeHash = getStoreHash(); | ||
const channelId = getChannelId(); | ||
|
||
// Not all sites have the channel-specific canonical URL backfilled. | ||
// Wait till MSF-2643 is resolved before removing and simplifying the endpoint logic. | ||
if (!channelId || channelId === '1') { | ||
return `https://store-${storeHash}.${graphqlApiDomain}/graphql`; | ||
} | ||
|
||
return `https://store-${storeHash}-${channelId}.${graphqlApiDomain}/graphql`; | ||
}; | ||
|
||
const generate = async () => { | ||
await generateSchema(getEndpoint(), { | ||
headers: { Authorization: `Bearer ${getToken()}` }, | ||
}); | ||
|
||
await generateTadaTypes(); | ||
}; | ||
|
||
generate(); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.