Skip to content

Mock generator for testing React with Apollo MockedProvider.

Notifications You must be signed in to change notification settings

csabat/react-apollo-testing-mock-gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React apollo testing mock generator

This packages generates mock responses based on your graphql query, in order to test your React component with MockedProvider.

Configuration

To initialise your config run:

mock-gen --init

Select your file extension preference, and provide the path to your schema file. ex. ./App/frontend/graphql/schema.graphql.

In your applications root folder mock-generator.config.js will be generated up on initialisation.

This is how it works

Get your .gql files relative path and run:

mock-gen ./App/frontend/Contact/graphql/contact.gql // <- your path

More on configuration

aliasPaths - an Object, defines you alias paths (if you use any) to help resolve fragments. ex:

aliasPaths: {
    "@yourAlias": './App/frontend'
},

lint - a function returns a string with your preferred lint command to format the generated file.

lint: (path) => `yarn eslint ${path} --fix`,

includeTypenames - a boolean whether you prefer the mock with typenames or without. resolvers - an Object defines all primitive grapqhl types and the way to resolve them (ex: with Faker.js).

resolvers: {
	String: {
		age: () => '23',
		name: () => "Josh Doe",
		default: () => 'random text'
	},
	etc...
	ScalarTypeDefinition: {
		// here comes your scalar definitions
		Date: {
			default: () => '2020-02-02'
		}
	},
}

Disclaimer

This package is still under development. The current version includes:

  • resolving fragments
  • resolving typenames
  • resolving alias paths
  • only works with .gql files
  • only works with one query defined

About

Mock generator for testing React with Apollo MockedProvider.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published