Skip to content

Instantly share code, notes, and snippets.

@dotansimha
Last active October 22, 2018 17:28
Show Gist options
  • Save dotansimha/672e629d4739986d189afe2c522f66c7 to your computer and use it in GitHub Desktop.
Save dotansimha/672e629d4739986d189afe2c522f66c7 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
const fs = require('fs');
fetch(`http://localhost:3002/graphql`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
variables: {},
operationName: '',
query: `
{
__schema {
types {
kind
name
possibleTypes {
name
}
}
}
}
`,
}),
})
.then(result => result.json())
.then(result => {
// here we're filtering out any type information unrelated to unions or interfaces
const filteredData = result.data.__schema.types.filter(
type => type.possibleTypes !== null,
);
result.data.__schema.types = filteredData;
fs.writeFile('./fragmentTypes.json', JSON.stringify(result.data), err => {
if (err) {
console.error('Error writing fragmentTypes file', err);
} else {
console.log('Fragment types successfully extracted!');
}
});
});
import * as introspectionQueryResultData from './fragmentTypes.json';
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData: introspectionQueryResultData as any,
});
export const client: ApolloClient<any> = new ApolloClient({
link,
cache: new InMemoryCache({ fragmentMatcher }),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment