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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
- name: Install
run: npm ci
- name: Test
run: npx jest --runInBand
run: npm test -- --runInBand --watchAll=false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ yarn-error.log*

# vercel
.vercel

# generated schema introspection
/lib/apolloClient/fragmentTypes.json
279 changes: 0 additions & 279 deletions lib/apolloClient/fragmentTypes.json

This file was deleted.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
},
"scripts": {
"dev": "next dev",
"predev": "node scripts/generate-fragment-types.js",
"build": "next build",
"prebuild": "node scripts/generate-fragment-types.js",
"start": "next start",
"prestart": "node scripts/generate-fragment-types.js",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"lint": "eslint .",
"test": "jest --watch"
"pretest": "node scripts/generate-fragment-types.js",
"test": "jest --watch",
"generate:fragment-types": "node scripts/generate-fragment-types.js"
},
"dependencies": {
"@apollo/client": "^3.14.0",
Expand Down
47 changes: 47 additions & 0 deletions scripts/generate-fragment-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require('fs');
const path = require('path');

const fetch = require('cross-fetch');
const { getIntrospectionQuery } = require('graphql');

const schemaUrl =
process.env.APOLLO_SCHEMA_URL ||
process.env.NEXT_PUBLIC_APOLLOS_API ||
'https://longhollow-cdn.global.ssl.fastly.net';

const outputPath = path.join(
__dirname,
'..',
'lib',
'apolloClient',
'fragmentTypes.json'
);

async function main() {
const query = getIntrospectionQuery({ descriptions: false });
const response = await fetch(schemaUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query }),
});

if (!response.ok) {
const bodyText = await response.text().catch(() => '');
throw new Error(
`Schema introspection failed (${response.status} ${response.statusText}). ${bodyText}`
);
}

const payload = await response.json();
if (payload.errors) {
throw new Error(`Schema introspection errors: ${JSON.stringify(payload.errors)}`);
}

fs.writeFileSync(outputPath, `${JSON.stringify(payload.data, null, 2)}\n`, 'utf8');
console.log(`Wrote ${outputPath}`);
}

main().catch(error => {
console.error('[generate-fragment-types]', error.message || error);
process.exit(1);
});