Comments (4)
Is definitely in graphql-js
, see this test:
from graphql.
oops.. ya, I am not sure how I missed it in the search. We don't use it now, so may keep this open to track it ???
from graphql.
Thanks @EmergentBehavior for pulling that out from graphql-js
.
For reference, here's the ported test:
Line 27 in d80cf86
To elaborate further on IsTypeOf
, it's usually would be used to check for the type of the value at runtime.
More specifically, for abstract types (i.e. interfaces and unions).
So a typical use-case would be when you have the following schema (as defined in the TestIsTypeOfUsedToResolveRuntimeTypeForInterface
test)
// Using GraphQL type system shorthand notation, refer to: http://graphql.org/docs/typesystem/
// `Pet` is an interface, with a `name` field
interface Pet {
name: String
}
// `Dog` implements `Pet`
type Dog : Pet {
name: String
woofs: Boolean
}
// `Cat` implements `Pet`
type Cat : Pet {
name: String
meows: Boolean
}
type Query {
pets: [Pet] // `pets` returns a list of `Pet` interface
}
So, given the following query:
query Q {
pets {
name
}
}
The Resolve
function for pets
field may return list of values that are of a Cat
type or a Dog
type (or any other type that implements Pet
interface).
IsTypeOf
function then will be executed at runtime to determine it's concrete type, i.e. if the value return is a Cat
type or a Dog
type.
Regarding it being on the spec, it is there but it's very subtle:
The interface type should have some way of determining which object a given result corresponds to. Once it has done so, the result coercion of the interface is the same as the result coercion of the object.
The union type should have some way of determining which object a given result corresponds to. Once it has done so, the result coercion of the union is the same as the result coercion of the object.
IsTypeOf
is just one way of implementing that spec.
Note that IsTypeOf
is defined in the concrete types (i.e. in graphql.ObjectConfig
)
You can also choose to define ResolveType
function in the abstract types (see graphql.InterfaceConfig
and graphql.UnionConfig
).
So graphql-js/graphql-go
provides two ways to satisfy the above specs.
Hope that make sense, cos it's past midnight here lol. Cheers!
from graphql.
@sogko thanks you so much for your time explaining it. I did a code search and missed the the usage (it was few commits behind). Thanks again.
from graphql.
Related Issues (20)
- New release?
- Potential goroutine leak in TestContextDeadline HOT 1
- Enums with trailing white space cause error.
- Playground
- make union input type ? it just have output union type
- With fiber HOT 1
- Printing GraphQL documents is slow HOT 1
- Bug with underscore and same name in keys from json response
- MongoDB _id field
- Printer returns invalid SDL if Block String comment contains double-quote
- When using custom scalar types, it's crucial to provide error feedback to users when issues arise with their submitted data. However, triggering exceptions within the ParseValue and ParseLiteral methods can lead to program crashes when using the graphql.Do method. This prevents the necessary error messages from being delivered to users.
- String type no longer recongised HOT 1
- Is it possible to go from `*graphql.Schema` to an ast node? HOT 1
- Error handling HOT 1
- Disabling Field Suggestions
- Is possible to typing typeConfig of graphql.Object after Object done.
- RootObjectFn request body always empty
- Unable to pass {{....}} as part of query or mutation string
- Redefining scalar ID
- How to support scalar JSON type? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql.