-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for property resolvers for interface types #429
Comments
By the way the error I get when I try to do this is: {
"code": "GRAPHQL_VALIDATION_FAILED",
"exception": {
"stacktrace": [
"GraphQLError: Cannot query field \"foo\" on type \"IExample\". Did you mean to use an inline fragment on \"ConcreteType\"?",
"..."
]
}
} |
You can't query interfaces, you can only implement them. EDIT: |
It's not related to NestJS, but rather the GraphQL itself |
I think you can, it clearly works for fields right on the object. I think that my problem may simply be that I didn't put the field on the interface though! I'll double check and follow up here. Thanks. |
@justinmchase nope you can't. |
Well they're doing it even in that example you linked... The character interface has a interface Character {
id: ID!
name: String!
friends: [Character]
appearsIn: [Episode]!
} query HeroForEpisode($ep: Episode!) {
hero(episode: $ep) {
name # <-- this is a field on the interface
... on Droid {
primaryFunction
}
}
} Imagine you want the |
Looking at this more, adding the field to the interface doesn't help. I am getting a crash in I think its legitimate because I am able to do this with graphql without using this library and it is documented in their documentation and it is a limitation of this library that this isn't supported. I think the example from the gql documentation for characters that @marcus-sa linked to is a good one, so this feature request / bug becomes how can I implement @InterfaceType()
export class Character {
@Field()
public name: string
}
@Resolver(of => Character ) // <-- this crashes my app
export class CharacterResolver {
constructor(
private readonly characters: CharacterService
) { }
@ResolveProperty(type => String)
public async name(@Root() character: Character) {
return this.charcters.resolveName(character)
}
} |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm submitting a...
[x] Feature request
Current behavior
I would like to create a resolver for an interface type which has a property resolver
Expected behavior
I should be able to define a resolver for an interface type and add property resolvers for virtual fields on that resolver. It should have access to services via constructor injection, etc.
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
If you have an interface type with multiple concrete types you want to be able to access it in gql like:
Not
Which it seems like right now the only way to do it is to promote the field to resolvers for each concrete type.
Environment
Nest version:
^6.7.2
For Tooling issues:
v12.8.0
linux
The text was updated successfully, but these errors were encountered: