Skip to content

Instantly share code, notes, and snippets.

@ConorCorp
Created June 27, 2023 13:19
Show Gist options
  • Save ConorCorp/b5db60799ec6dac42cf32dc610998434 to your computer and use it in GitHub Desktop.
Save ConorCorp/b5db60799ec6dac42cf32dc610998434 to your computer and use it in GitHub Desktop.
Load a schema with `@graphql-tools/url-loader` from a url, into a file.
import { loadSchema } from '@graphql-tools/load';
import { UrlLoader } from '@graphql-tools/url-loader';
import { writeFile } from 'fs';
import { printSchema } from 'graphql';
/*
* Script that loads cms's graphql schema from localhost instance.
*
* See docs here: https://the-guild.dev/graphql/tools/docs/schema-loading
*/
async function main() {
const schema = await loadSchema('http://localhost:1337/graphql', {
loaders: [new UrlLoader()],
});
writeFile('./__generated__/schema.graphql', printSchema(schema), (err) => {
if (err) {
console.error(err);
}
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment