Weave
In GQLoom, the weave
function is used to weave multiple Resolvers or Silks into a single GraphQL Schema.
The weave
function can take resolver, silk, weaver configuration, global middleware
Weaving resolvers
The most common usage is to weave multiple resolvers together, for example:
Weaving a single silk
Sometimes we need to weave a single silk woven into a GraphQL Schema, for example:
Weaver configuration
Input type naming conversion
In GraphQL, objects are recognized as type and input.
When using GQLoom
, we usually only use the object
type, and behind the scenes GQLoom
will automatically convert the object
type to the input
type.
The advantage of this is that we can use the object
type directly to define input parameters without having to define the input
type manually.
However, when we use the same object
type for both type
and input
, it will not be woven into GraphQL Schema due to naming conflict.
Let's look at an example:
In the above code, we defined a Cat
object and used it for type
and input
. But when we try to weave catResolver
into the GraphQL Schema, an error is thrown with a duplicate Cat
name:
To solve this problem, we need to specify a different name for the input
type. We can do this using the getInputObjectName
option in the SchemaWeaver.config
configuration:
Thus, Cat
objects will be converted to CatInput
types, thus avoiding naming conflicts.
The above catResolver
will weave the following GraphQL Schema:
Global middleware
See more about middleware usage in middleware section.