@fruits-chain/qiufen-pro-graphql-mock
- Mock your GraphQL data based on a schema.
Install
yarn add @fruits-chain/qiufen-pro-graphql-mock -D
Usage
- step1:Create the "qiufen.config.js" configuration file in the project root directory.
- step2:Configure the type of the object
interface GraphqlKitConfig {
port: number
endpoint: ServiceConfig
localSchemaFile?: string
schemaPolicy?: SchemaPolicy
mock?: MockConfig
}
interface ServiceConfig {
url: string
}
interface MockConfig {
scalarMap: any
resolvers?: any
}
type SchemaPolicy = 'local' | 'remote'
interface PlaygroundConfig {
headers?: Record<string, string>
}
- step3:Go to configure "qiufen.config.js".
const Mock = require('mockjs')
const { GraphqlKitConfig } = require('@fruits-chain/qiufen-pro-graphql-mock')
const { Random } = Mock
const config = {
port: 4200,
localSchemaFile: './src/graphql/generated/schema.graphql',
schemaPolicy: 'remote',
endpoint: {
url: 'http://localhost:4000/graphql',
},
mock: {
scalarMap: {
Int: () => Random.integer(0, 100),
String: () => Random.ctitle(2, 4),
ID: () => Random.id(),
Boolean: () => Random.boolean(),
BigDecimal: () => Random.integer(0, 1000000),
Float: () => Random.float(0, 100),
Date: () => Random.date(),
DateTime: () => Random.datetime(),
Long: () => Random.integer(0, 10000),
NumberOrBoolOrStringOrNull: () => null,
NumberOrString: () => null,
Object: () => ({}),
},
resolvers: {
Query: {
},
},
},
}
module.exports = config
const {
executeQiufenMockingServer,
} = require('@fruits-chain/qiufen-pro-graphql-mock')
executeQiufenMockingServer()
- step5:
If you want to customize the configuration
import { startMockingServer } = require('@fruits-chain/qiufen-pro-graphql-mock')
startMockingServer(config)