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:69

Methods#

get#

get<KeyT, ReturnKeyT\>(args: GetArgs<KeyT\>): 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');
&gt; { $ref: { key: 'abc-737dh-djdjd', typeName: 'User' } }
store.get('User', 'abc-737dh-djdjd', 'name')
&gt; "Hello World"

Type parameters:#

NameTypeDefault
KeyTKeyTypeConstraintsstring
ReturnKeyTKeyTypeConstraintsstring

Parameters:#

NameType
argsGetArgs<KeyT\>

Returns: unknown

Defined in: packages/mock/src/types.ts:90

get<KeyT, ReturnKeyT\>(typeName: string, key: KeyT, fieldNameOrFieldNames: string | string[], fieldArgs?: string | { [argName: string]: any; }): unknown

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

Type parameters:#

NameTypeDefault
KeyTKeyTypeConstraintsstring
ReturnKeyTKeyTypeConstraintsstring

Parameters:#

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

Returns: unknown

Defined in: packages/mock/src/types.ts:96

get<KeyT\>(typeName: string, keyOrDefaultValue?: KeyT | { [fieldName: string]: any; }, defaultValue?: { [fieldName: string]: any; }): unknown

Get a reference to the type.

Type parameters:#

NameTypeDefault
KeyTKeyTypeConstraintsstring

Parameters:#

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

Returns: unknown

Defined in: packages/mock/src/types.ts:105

get<KeyT, ReturnKeyT\>(ref: Ref<KeyT\>, fieldNameOrFieldNames: string | string[], fieldArgs?: string | { [argName: string]: any; }): unknown

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

Type parameters:#

NameTypeDefault
KeyTKeyTypeConstraintsstring
ReturnKeyTKeyTypeConstraintsstring

Parameters:#

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

Returns: unknown

Defined in: packages/mock/src/types.ts:117


set#

set<KeyT\>(args: SetArgs<KeyT\>): 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:#

NameTypeDefault
KeyTKeyTypeConstraintsstring

Parameters:#

NameType
argsSetArgs<KeyT\>

Returns: void

Defined in: packages/mock/src/types.ts:153

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

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

Type parameters:#

NameTypeDefault
KeyTKeyTypeConstraintsstring

Parameters:#

NameType
typeNamestring
keyKeyT
fieldNamestring
value?unknown

Returns: void

Defined in: packages/mock/src/types.ts:158

set<KeyT\>(typeName: string, key: KeyT, values: { [fieldName: string]: any; }): void

Set the given field values to the type with key.

Type parameters:#

NameTypeDefault
KeyTKeyTypeConstraintsstring

Parameters:#

NameType
typeNamestring
keyKeyT
valuesobject

Returns: void

Defined in: packages/mock/src/types.ts:163

set<KeyT\>(ref: Ref<KeyT\>, fieldName: string, value?: unknown): void

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

Type parameters:#

NameTypeDefault
KeyTKeyTypeConstraintsstring

Parameters:#

NameType
refRef<KeyT\>
fieldNamestring
value?unknown

Returns: void

Defined in: packages/mock/src/types.ts:172

set<KeyT\>(ref: Ref<KeyT\>, values: { [fieldName: string]: any; }): void

Set the given field values to the type with ref.

Type parameters:#

NameTypeDefault
KeyTKeyTypeConstraintsstring

Parameters:#

NameType
refRef<KeyT\>
valuesobject

Returns: void

Defined in: packages/mock/src/types.ts:177