Last active
October 22, 2018 17:28
-
-
Save dotansimha/672e629d4739986d189afe2c522f66c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!'); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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