-
How to achieve nested encapsulation?Repo for this example can be found here: https://github.com/Everettss/question-graphql-mesh In the starting example there is one level of encapsulation,
sources:
- name: Wikimedia
handler:
openapi:
source: https://api.apis.guru/v2/specs/wikimedia.org/1.0.0/swagger.yaml
transforms:
- prefix:
value: Wikimedia_
- encapsulate:
name: wikimedia
applyTo:
query: true
mutation: false
subscription: false
- name: Healthcare
handler:
openapi:
source: https://api.apis.guru/v2/specs/healthcare.gov/1.0.0/openapi.yaml
transforms:
- prefix:
value: Healthcare_
- encapsulate:
name: healthcare
applyTo:
query: true
mutation: false
subscription: false This type Query {
healthcare: healthcareQuery
wikimedia: wikimediaQuery
} To execute this query I run query currentQuery {
healthcare {
getApiArticlesMediaTypeExtension(mediaTypeExtension: _JSON) {
articles {
date
}
}
}
wikimedia {
getFeedAvailability {
inTheNews
}
}
} My question is how to modify this example to wrap fields type NestedType {
healthcare: healthcareQuery
wikimedia: wikimediaQuery
}
type Query {
nestedType: NestedType
} So I could query this schema by: query desiredQuery {
nestedType {
healthcare {
getApiArticlesMediaTypeExtension(mediaTypeExtension: _JSON) {
articles {
date
}
}
}
wikimedia {
getFeedAvailability {
inTheNews
}
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The key to answer is to add an resolver for const resolvers = {
Query: {
nestedType: () => ({})
},
};
module.exports = { resolvers }; Next add additional resolvers for those fields in additionalTypeDefs: |
type NestedType {
healthcare: healthcareQuery
wikimedia: wikimediaQuery
}
extend type Query {
nestedType: NestedType
}
additionalResolvers:
- targetTypeName: NestedType
targetFieldName: wikimedia
sourceName: Wikimedia
sourceTypeName: Query
sourceFieldName: wikimedia
- targetTypeName: NestedType
targetFieldName: healthcare
sourceName: Healthcare
sourceTypeName: Query
sourceFieldName: healthcare
- ./additional-resolvers.js And finally remove transforms:
- filterSchema:
filters:
- Query.!{wikimedia,healthcare} |
Beta Was this translation helpful? Give feedback.
The key to answer is to add an resolver for
nestedType
like in file./additional-resolvers.js
Next add additional resolvers for those fields in
.meshrc.yaml