Documentation
API Reference
Interfaces
IMockStore

graphql-tools-monorepo / mock/src / IMockStore

Interface: IMockStore

mock/src.IMockStore

Implemented by

Table of contents

Properties

Methods

Properties

schema

schema: GraphQLSchema

Defined in

packages/mock/src/types.ts:83

Methods

get

get<KeyT, ReturnKeyT>(args): unknown

Get a field value from the store for the given type, key and field name — and optionally field arguments. If the field name is not given, a reference to the type will be returned.

If the the value for this field is not set, a value will be generated according to field return type and mock functions.

If the field’s output type is a ObjectType (or list of ObjectType), it will return a Ref (or array of Ref), ie a reference to an entity in the store.

Example:

store.get('Query', 'ROOT', 'viewer');
> { $ref: { key: 'abc-737dh-djdjd', typeName: 'User' } }
store.get('User', 'abc-737dh-djdjd', 'name')
> "Hello World"

Type parameters

NameType
KeyTextends KeyTypeConstraints = string
ReturnKeyTextends KeyTypeConstraints = string

Parameters

NameType
argsGetArgs<KeyT>

Returns

unknown

Defined in

packages/mock/src/types.ts:104

get<KeyT, ReturnKeyT>(typeName, key, fieldNameOrFieldNames, fieldArgs?): unknown

Shorthand for get({typeName, key, fieldName, fieldArgs}).

Type parameters

NameType
KeyTextends KeyTypeConstraints = string
ReturnKeyTextends KeyTypeConstraints = string

Parameters

NameType
typeNamestring
keyKeyT
fieldNameOrFieldNamesstring | string[]
fieldArgs?string | { [argName: string]: any; }

Returns

unknown

Defined in

packages/mock/src/types.ts:110

get<KeyT>(typeName, keyOrDefaultValue?, defaultValue?): unknown

Get a reference to the type.

Type parameters

NameType
KeyTextends KeyTypeConstraints = string

Parameters

NameType
typeNamestring
keyOrDefaultValue?KeyT | { [fieldName: string]: any; }
defaultValue?Object

Returns

unknown

Defined in

packages/mock/src/types.ts:119

get<KeyT, ReturnKeyT>(ref, fieldNameOrFieldNames, fieldArgs?): unknown

Shorthand for get({typeName: ref.$ref.typeName, key: ref.$ref.key, fieldName, fieldArgs})

Type parameters

NameType
KeyTextends KeyTypeConstraints = string
ReturnKeyTextends KeyTypeConstraints = string

Parameters

NameType
refRef<KeyT>
fieldNameOrFieldNamesstring | string[]
fieldArgs?string | { [argName: string]: any; }

Returns

unknown

Defined in

packages/mock/src/types.ts:131


has

has<KeyT>(typeName, key): boolean

Checks if a mock is present in the store for the given typeName and key.

Type parameters

NameType
KeyTextends KeyTypeConstraints = string

Parameters

NameType
typeNamestring
keyKeyT

Returns

boolean

Defined in

packages/mock/src/types.ts:208


reset

reset(): void

Resets the mock store

Returns

void

Defined in

packages/mock/src/types.ts:213


set

set<KeyT>(args): void

Set a field value in the store for the given type, key and field name — and optionally field arguments.

If the the field return type is an ObjectType or a list of ObjectType, you can set references to other entity as value:

// set the viewer name
store.set('User', 1, 'name', 'Alexandre);
store.set('Query', 'ROOT', 'viewer', store.get('User', 1));
 
// set the friends of viewer
store.set('User', 2, 'name', 'Emily');
store.set('User', 3, 'name', 'Caroline');
store.set('User', 1, 'friends', [store.get('User', 2), store.get('User', 3)]);

But it also supports nested set:

store.set('Query', 'ROOT', 'viewer', {
 name: 'Alexandre',
 friends: [
   { name: 'Emily' }
   { name: 'Caroline }
 ]
});

Type parameters

NameType
KeyTextends KeyTypeConstraints = string

Parameters

NameType
argsSetArgs<KeyT>

Returns

void

Defined in

packages/mock/src/types.ts:167

set<KeyT>(typeName, key, fieldName, value?): void

Shorthand for set({typeName, key, fieldName, value}).

Type parameters

NameType
KeyTextends KeyTypeConstraints = string

Parameters

NameType
typeNamestring
keyKeyT
fieldNamestring
value?unknown

Returns

void

Defined in

packages/mock/src/types.ts:172

set<KeyT>(typeName, key, values): void

Set the given field values to the type with key.

Type parameters

NameType
KeyTextends KeyTypeConstraints = string

Parameters

NameType
typeNamestring
keyKeyT
valuesObject

Returns

void

Defined in

packages/mock/src/types.ts:182

set<KeyT>(ref, fieldName, value?): void

Shorthand for set({ref.$ref.typeName, ref.$ref.key, fieldName, value}).

Type parameters

NameType
KeyTextends KeyTypeConstraints = string

Parameters

NameType
refRef<KeyT>
fieldNamestring
value?unknown

Returns

void

Defined in

packages/mock/src/types.ts:191

set<KeyT>(ref, values): void

Set the given field values to the type with ref.

Type parameters

NameType
KeyTextends KeyTypeConstraints = string

Parameters

NameType
refRef<KeyT>
valuesObject

Returns

void

Defined in

packages/mock/src/types.ts:200