Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this? Shouldn't this point to bigcommerce-graphql.d.ts now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While in Multi-schema mode, since generateOutput produces an introspection file for each GraphQL schema in the tsconfig plugin schemas array, we can't pass it a single file name - instead, generateOutput will create a file for each tadaOutputLocation key in each schema config object 🙂

If we try to manually set this to:

await generateOutput({
  disablePreprocessing: false,
  output: join(__dirname, '../bigcommerce-graphql.d.ts'),
  tsconfig: undefined,
});

We get the following:
Screenshot 2024-06-07 at 2 24 48 PM

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