How to use graphql-faker - 1 common examples

To help you get started, we’ve selected a few graphql-faker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samdenty / gqless / internal / fixtures / demoSchema / fetchQuery.ts View on Github external
// @ts-ignore
import { mergeWithFakeDefinitions } from 'graphql-faker/dist/fake_definition'
import {
  fakeTypeResolver,
  fakeFieldResolver,
  // @ts-ignore
} from 'graphql-faker/dist/fake_schema'
import { QueryFetcher } from 'gqless'

const SEED = 123

const idl = fs.readFileSync(
  path.join(__dirname, './demoSchema.graphql'),
  'utf-8'
)
const schema = buildASTSchema(mergeWithFakeDefinitions(parse(idl)))

export const fetchQuery: QueryFetcher = async (
  query: string,
  variables?: any
): Promise => {
  seed(SEED)
  const response = await execute(
    schema,
    parse(query),
    undefined,
    undefined,
    variables,
    undefined,
    fakeFieldResolver,
    fakeTypeResolver
  )

graphql-faker

Mock or extend your GraphQL API with faked data. No coding required

MIT
Latest version published 1 year ago

Package Health Score

51 / 100
Full package analysis

Similar packages