Expose a JS API (for use within Node.JS / browser?)
This tool would be super-useful inside tests, but it currently requires starting a HTTP server - which is not ideal.
If the API provided a way to provide a seed to the randomness, it would allow for the predictability required in tests
@samdenty You can try to use fakeSchema directly:
https://github.com/APIs-guru/graphql-faker/blob/master/src/fake_schema.ts#L66
Just build your SDL with buildSchema before passing it to fakeSchema.
@samdenty You can try to use
fakeSchemadirectly: https://github.com/APIs-guru/graphql-faker/blob/master/src/fake_schema.ts#L66 Just build your SDL withbuildSchemabefore passing it tofakeSchema.
fakeSchema isn't exposed through the lib though. You can import it directly through const fakeSchema = require('graphql-faker/dist/fake_schema').fakeSchema but it doesn't seem to work with a basic use case.
@jsphweid See here for a example of how I used it, for Jest tests
How comfortable are the maintainers with people using this API directly? This is exactly what I want, happy to help out making it a fully supported API if needs be.
@TimPerry I'm in a process of switching to the new internal API based on default resolvers: https://github.com/graphql/graphql-js/pull/1332 After that is done I have no problem if someone export and document default field and type resolvers.
Awesome, sounds great.
@TimPerry As promised, I switched internal implementation to expose fakeTypeResolver & fakeFieldResolver in 6b3e743e59977c7437f395efc5b2a0fde45f1151 and released it 2.0.0-rc.8 📦
@IvanGoncharov It would be handy if you could export a function from the index, eg.
import { seed } from 'faker'
export const executeQuery = (idlPath: string, query: DocumentNode, variables?): Promise<{data,errors}> => {
seed(123)
}
so we don't have to directly use private APIs