Open
Description
Discussed in #4042
Originally posted by wmwart December 22, 2021
Good afternoon.
I have a question about using stitchSchemas with namespaced queries and mutations.
I have 2 remote services:
###AssetService
type Asset {
id: ID!
name: String!
description: String
...
}
type AssetPayload {
item: Asset
}
type AssetsPayload {
items: [Asset!]
pageInfo: PaginationInfo
}
input AssetWhereUniqueInput {
id: ID
}
type AssetQuery {
getOne(where: AssetWhereUniqueInput!): AssetPayload! @withAuth
getList(filter: AssetFilter = {} sort: [AssetSort! ] = [{id: asc}] page: Int = 1 perPage: Int = 100): AssetsPayload! @withAuth
getMany(ids: [ID!]!): AssetsPayload! @withAuth
}
type AssetMutation {
create(input: AssetCreateInput!): AssetPayload! @withAuth
update( where: AssetWhereUniqueInput! input: AssetUpdateInput!): AssetPayload! @withAuth
remove(where: AssetWhereUniqueInput!): AssetPayload! @withAuth
restore(where: AssetWhereUniqueInput!): AssetPayload! @withAuth
delete(where: AssetWhereUniqueInput!): AssetPayload! @withAuth
}
type Query {
Asset: AssetQuery
}
type Mutation {
Asset: AssetMutation
}
...
and
### AssetClassService
type AssetClass {
id: ID!
name: String!
assets: [AssetWithoutAssetClass!]!
}
type AssetClassPayload {
item: AssetClass
}
type AssetClassesPayload {
items: [AssetClass!]
pageInfo: PaginationInfo
}
type AssetClassQuery {
getOne(where: AssetClassWhereUniqueInput!): AssetClassPayload! @withAuth
getList(filter: AssetClassFilter = {} sort: [AssetClassSort! ] = [{id: asc}] page: Int = 1 perPage: Int = 100): AssetClassesPayload! @withAuth
getMany(ids: [ID!]): [AssetClass!]!
}
type AssetClassMutation {
create(input: AssetClassCreateInput!): AssetClassPayload! @withAuth
update( where: AssetClassWhereUniqueInput! input: AssetClassUpdateInput!): AssetClassPayload! @withAuth
remove(where: AssetClassWhereUniqueInput!): AssetClassPayload! @withAuth
restore(where: AssetClassWhereUniqueInput!): AssetClassPayload! @withAuth
delete(where: AssetClassWhereUniqueInput!): AssetClassPayload! @withAuth
}
type Asset {
id: ID!
assetClass: AssetClass
}
type AssetQuery {
getMany(ids: [ID!]!): [Asset!]!
}
type Query {
AssetClass: AssetClassQuery
Asset: AssetQuery
}
type Mutation {
AssetClass: AssetClassMutation
}
Thus, when using stitchSchemas in my proxy service, a function for obtaining a stitched schema appeared:
const makeGatewaySchema = async () => {
const assetServiceExecutor = makeRemoteExecutor('http://localhost:7702', { log: true });
const assetClassServiceExecutor = makeRemoteExecutor('http://localhost:7703', { log: true });
return stitchSchemas({
subschemas: [
{
schema: await introspectSchema(assetServiceExecutor),
executor: assetServiceExecutor,
merge: {...}
},
{
schema: await introspectSchema(assetClassServiceExecutor),
executor: assetClassServiceExecutor,
merge: {...}
},
],
});
}
Which allows me to fulfill the request:
query Items {
Asset {
getList {
items {
id
name
assetClass {
id
name
description
}
}
}
}
}
However, none of the combination of merge
options of these subcircuits specified in the documentation and examples of use returned me the required answer.
I assume that the problem is precisely in the namespaced types.
Please help me specify the correct settings for merge
options or share a link to a solution to a similar problem