apollo-graphql-tutorial | Learning apollographql version 2.x with Node.js | GraphQL library
kandi X-RAY | apollo-graphql-tutorial Summary
kandi X-RAY | apollo-graphql-tutorial Summary
Learning apollographql version 2.x with Node.js
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of apollo-graphql-tutorial
apollo-graphql-tutorial Key Features
apollo-graphql-tutorial Examples and Code Snippets
Community Discussions
Trending Discussions on apollo-graphql-tutorial
QUESTION
I have looked this question: How to use or resolve enum types with graphql-tools?
And, this doc: https://www.apollographql.com/docs/graphql-tools/scalars/#internal-values
Now, I want to custom the value of graphql enum
.
typeDefs.ts
:
ANSWER
Answered 2019-Oct-15 at 14:17The internal values you specify for a GraphQL enum are just that -- internal. This is stated in the documentation:
These don't change the public API at all, but they do allow you to use that value instead of the schema value in your resolvers
If you map the enum value DESKTOP
to the internal value Computers
, only the behavior of your resolvers will be affected. Specifically:
- If a field takes an argument of the type
Device
and the argument is passed the valueDESKTOP
, the value actually passed to the resolver function will beComputers
. - If a field itself has the type device and we want to return
DESKTOP
, inside our resolver, we will need to returnComputers
instead.
Take for example a schema that looks like this:
QUESTION
graphql service 1 type defs:
...ANSWER
Answered 2019-Jul-26 at 11:56It's important to keep in mind that makeRemoteExecutableSchema
just "uses the [provided] link to delegate requests to the underlying service". When you query fields from the remote schema, it's delegating the request for those particular fields to the remote server, effectively rerouting the request. This is true whether you stitch the schema with some other one, or use it by itself.
Schema stitching allows you to combine any number of local and remote schemas. However, any remote schemas will still have their fields resolved by their respective servers.
Because stitching merges the provided schemas' type definitions, you can use the extend
keyword inside one schema to modify types from another, even if it's a remote schema. If we extend an object type, we can also add some resolvers to help resolve the fields we've added.
Extending a remote schema's input object is a bit different. There's no "resolving" input objects. Instead, all we do by extending it is saying "these fields are also valid". However, when we request some remote schema field that takes this modified input object as an argument, the resolution of this field is, again, delegated to the underlying remote schema. It gets the modified input object and when it validates it, it finds extra fields and throws an error.
In other words, it's not possible to extend input types like this. And consider, even if the request didn't fail validation -- even if you extend the input type, the original resolver has not been changed and so it necessarily won't know how to handle the additional input type fields anyway.
NOTE: If you do the above but with two local schemas, the extension should work as expected because there is no delegation in this case. You're still left with a resolver that doesn't necessarily know how to handle the new input object field though.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install apollo-graphql-tutorial
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page