graphql-tools-monorepo / mock/src / IMockStore
Interface: IMockStore
mock/src.IMockStore
Implemented by
Table of contents
Properties
Methods
Properties
schema
• schema: GraphQLSchema
Defined in
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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
ReturnKeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
args | GetArgs <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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
ReturnKeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
typeName | string |
key | KeyT |
fieldNameOrFieldNames | string | 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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
typeName | string |
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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
ReturnKeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
ref | Ref <KeyT > |
fieldNameOrFieldNames | string | 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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
typeName | string |
key | KeyT |
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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
args | SetArgs <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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
typeName | string |
key | KeyT |
fieldName | string |
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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
typeName | string |
key | KeyT |
values | Object |
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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
ref | Ref <KeyT > |
fieldName | string |
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
Name | Type |
---|---|
KeyT | extends KeyTypeConstraints = string |
Parameters
Name | Type |
---|---|
ref | Ref <KeyT > |
values | Object |
Returns
void