resolveArrayByClass ⇒ Promise<Array<Attributes>>
resolveArrayByClass(SequelizeClass
, withMethods :Boolean=false
) ⇒ Promise<Array<Attributes>>
First, it internally resolves an an Array
of SequelizeModel instances
that are of the passed-in SequelizeClass. Then it converts the Array
into a
promised Array
of Attributes objects.
Returns: Promise<Array<Attributes>>
Param | Type | Description |
---|---|---|
SequelizeClass |
Class |
A specific SequelizeClass to process. |
withMethods |
Boolean |
Populate Attributes objects with sequelize methods |
Module Import
import { resolveModelsByClass } from 'sequelize-relay';
About
The resolveArrayByClass
combines resolveModelsByClass and getArrayData
into one function for easier use of the API.
In a nut shell:
resolveModelsByClass(ClassName)
=== getArrayData(resolveModelsByClass(ClassName));
For more detailed documentation see resolveModelsByClass and getArrayData.
Examples
Consider the following GraphQL Schema Type for queryType
:
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
people: {
description: 'People',
type: personConnection,
args: connectionArgs,
resolve: (root, args) =>
connectionFromPromisedArray(resolveArrayByClass(Person), args)
},
peopleWithMethods: {
description: 'People with methods',
type: personConnection,
args: connectionArgs,
resolve: (root, args) =>
connectionFromPromisedArray(resolveArrayByClass(Person, true), args)
},
articles: {
description: 'Articles',
type: articleConnection,
args: connectionArgs,
resolve: (root, args) =>
connectionFromPromisedArray(resolveArrayByClass(Article), args)
},
node: nodeField
})
});
For more information about connectionArgs
and connectionFromPromisesdArray
, click here.
From there, we are able to pass graphql-relay queries like so:
{
peopleWithMethods(first: 2) {
pageInfo {
startCursor
hasNextPage
}
edges {
cursor
node {
id
givenName
familyName
address
}
}
}
}
{
articles(first: 2) {
pageInfo {
startCursor
hasNextPage
}
edges {
cursor
node {
id
givenName
familyName
address
}
}
}
}
More Examples
You can view more examples by reviewing the source code:
- Full Person Model Example from test source
- Full GraphQL Setup Example from test source