-
Notifications
You must be signed in to change notification settings - Fork 146
Support for InlineFragments #103
Comments
I'm very keen to have this too - it's pretty crippling not being able to use interfaces. |
@kipz You could try out the changes I've done in my fork, it works for non-custom queries. |
Thanks @Duske, but I'm having a little difficulty rebasing your fork with current upstream/master as there have been changes to the same areas. In no small part due to master being broken right now! |
Ah, now I see the current code. Before the support of relation types the code was already hard to understand, but now the else part is huge. I don't know how to get the inlinefragments to work with this mess 😕 |
I've taken a stab at this today. So far I'm able to generate the correct Cypher queries to resolve the data, however it seems graphql-js expects resolvers for interface types to return an object that it can call
with type Genre implements Attribute {
name: String
movies: [Movie] @relation(name: "IN_GENRE", direction: "IN")
}
interface Attribute {
name: String
} @Duske did you encounter this in your implementation? |
@johnymontana Thank you very much for looking into this issue :) Yeah I encountered this problem as well and wrote a resolveType function. Then you can write a resolveType function like this: const resolverMap = {
Genre: {
__resolveType(obj, context, info){
return obj["FRAGMENT_TYPE"]; // which is "Genre"
},
//next implementation of Attribute
},
}; Note that the |
@Duske ah, cool. I'll give that a try. Thanks! |
I've added initial support for InlineFragments based on @Duske's suggestions above. Thanks @Duske! This is included in the recent v1.0.1 release on NPM. A few notes:
|
Thank you for working on this :) I've tested the release in our project and noticed two bugs, which are mentioned and possibly solved in #114 and #115. A feature which seems to be missing for now is to access the related subnodes of an inlinefragment. Example schema
Example GraphQL- and Cypher-Query
As you can see, the |
Nice, thank you 👍 I've noticed another aspect we need to consider when implementing this feature. Let's suppose we have the following query added to the schema.
So basically a query, which directly returns nodes implementing the interface A GraphQL query could look like this:
The problem is here, that the cypher query will first match all nodes with label
Instead, for each inlinefragment with type there should be a MATCH clause like What do you think? Is this reasonable and/or feasible? |
@Duske This look like it Require some kind of Union support. https://graphql.org/learn/schema/#union-types Is this supported now? |
@obarbier did you find a solution for the union? |
+1 Union needed. Is it supported now? |
Hey all, is there any documentation on the neo4j-graphql-js Interface support to the extents it's implemented? Interfaces are still marked as unsupported in the Grandstack docs. |
@flazoon This looks really good, unfortunately I cannot test it the following days. Feel free to close this issue if fixed, awesome work! |
@benjamin-rood I guess I was referring to @Duske's comment from Oct 3, 2018. I guess that query should work with 2.9.3+. |
@flazoon Unfortunately still broken for unions, but it shouldn't make a difference: in both cases there needs to be generated a resolver function for either the interface or union type Without this, how can inline fragments be working? |
Much more robust support for intefaces and unions was added in the most recent release v2.13.0, including generation of Closing this issue as it originally pertained to use of inline fragments, please open new issue if you're seeing specific problems related to interface and union types. |
It would be awesome if we support inlineFragments in order to use interface appropriately.
I've been tinkering on a basic prototype in this fork and got inlineFragments for non-custom queries working.
The approach is not very clean, but maybe it can be a first step for InlineFragment support :)
What do you think?
The text was updated successfully, but these errors were encountered: