Skip to content

Commit

Permalink
feat: provider-specific graphql file naming convention (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewvolk committed Jun 10, 2024
1 parent 0cd5a29 commit b8ea900
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-adults-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Introduces more consistent naming convention for files related to GraphQL, changes opinions around when it is appropriate to track GraphQL files in version control, fixes an issue where the `generate.cjs` script was swallowing helpful error messaging
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ dist
test-results/
playwright-report/
playwright/.cache/
graphql-env.d.ts
bigcommerce.graphql
bigcommerce-graphql.d.ts
.DS_Store
1 change: 0 additions & 1 deletion core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ next-env.d.ts

# generated
client/generated
schema.graphql

# secrets
.catalyst
2 changes: 1 addition & 1 deletion core/client/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { initGraphQLTada } from 'gql.tada';

import type { introspection } from '~/graphql-env';
import type { introspection } from '~/bigcommerce-graphql';

export const graphql = initGraphQLTada<{
introspection: introspection;
Expand Down
30 changes: 18 additions & 12 deletions core/scripts/generate.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,24 @@ const getEndpoint = () => {
};

const generate = async () => {
await generateSchema({
input: getEndpoint(),
headers: { Authorization: `Bearer ${getToken()}` },
output: join(__dirname, '../schema.graphql'),
tsconfig: undefined,
});

await generateOutput({
disablePreprocessing: false,
output: join(__dirname, '../graphql-env.d.ts'),
tsconfig: undefined,
});
try {
await generateSchema({
input: getEndpoint(),
headers: { Authorization: `Bearer ${getToken()}` },
output: join(__dirname, '../bigcommerce.graphql'),
tsconfig: undefined,
});

await generateOutput({
disablePreprocessing: false,
output: undefined,
tsconfig: undefined,
});
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
process.exit(1);
}
};

generate();
11 changes: 8 additions & 3 deletions core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
},
{
"name": "@0no-co/graphqlsp",
"schema": "./schema.graphql",
"tadaOutputLocation": "./graphql-env.d.ts",
"trackFieldUsage": false,
"shouldCheckForColocatedFragments": false
"shouldCheckForColocatedFragments": false,
"schemas": [
{
"name": "bigcommerce",
"schema": "./bigcommerce.graphql",
"tadaOutputLocation": "./bigcommerce-graphql.d.ts"
}
]
}
],
"baseUrl": ".",
Expand Down

0 comments on commit b8ea900

Please sign in to comment.