-
Notifications
You must be signed in to change notification settings - Fork 146
Add Schema Stitching Example #550
base: master
Are you sure you want to change the base?
Conversation
Why are these files executable at all?
|
Hi @roschaefer, thanks for an example using schema stitching, I am curious, how you will compare this with the apollo federation approach? Thanks |
|
Looks like there are a few files too many in the root directory. Don't forget to remove them. |
36e6883 to
fdcab14
Compare
Thanks a million! |
The crucial difference is that in GraphQL schema stitching, the subschemas don't know each other. They are autonomous. See this blog post: https://product.voxmedia.com/2020/11/2/21494865/to-federate-or-stitch-a-graphql-gateway-revisited I must admit, I haven't used Apollo Federation myself in production. My goal in another project was that I used a remote GraphQL schema at https://graphcms.com/. Their schema would do a lot, but I wanted to implement my own authentication/authorization, data validation and custom logic. It didn't seem possible with Apollo Federation because I have no control over the schema at GraphCMS. However, with GraphQL schema stitching, this is possible and works beautifully. My architecture looks like this: Now, after I accomplished that, the idea came to my mind to use the same technique for I think the main advantage of this strategy is that it defeats the tight coupling between type-defintions and resolvers. This is by design since But doing it this way, I have all the freedom I want regarding my custom type definitions and still get all the convenience which Does that make sense @XBeg9 ? |
c1d1255 to
ef1b6c9
Compare
|
Looks like there are still 3 empty files in root which don't belong there. Maybe its a GitHub issue showing these or I am misinterpreting these? I like the example! |
ef1b6c9 to
24beba5
Compare
Thanks, typo is fixed now. This PR waits for #549 to be merged, that's why you see those three files in the PR. It's just UNIX file permissions, no changes to the content. |
This creates an example repository in
/examplesto showcase how the freshly renovated graphql schema stitching API can be leveraged forneo4j-graphql-js.When I was working on Oclelot-Social (formerly known as Human Connection) I made first-had experience of the advantages and disadvantages of
neo4j-graphql-js.Our biggest pain point with
neo4j-graphql-jswas the difficulty to customize the schema and write our own custom code aside of CRUD operations. I wished GraphQL Stitching had existed back then, because it's solving that problem beautifully.No more custom fallback type resolvers
Use case: You mix your own mutation/query resolvers with those of
neo4j-graphql-js. Unfortunately, you bypassneoj4-graphql-jsthen. If your custom resolver returns a type defined also yourneo4j-graphqj-jsschema, good luck writing all the code to fetch the associated data. We wrote our own "fallback resolvers" which checked if aparent.fieldwas already set (then it's most likely populated byneo4j-graphql-js) and otherwise make another database call to fetch it.Solution with grapqhl schema stitching: Write your own custom stuff and then call
delegateToSchemawith a query operation on the type you want to return. 🎉No more man-in-the-middle attacks on
resolveInfoUse-case: Your custom resolvers need data which may not be requested by the client. We "hacked" the
resolveInfoobject to request certain fields (e.g.id,createdAtordisabled) even if they weren't requested by the client. We would pass this manipulatedresolveInfotoneo4j-graphql-js. That way we could makeneo4j-graphql-jsreturn all properties of the nodes which we needed.Solution with grapqhl schema stitching: You specify
selectionSetin your resolver. 🎉Implement performant orderBy of aggregated data
We ran into performance issues while ordering by fields that have a
@cypherdirective. You could even use Schema Stitching as a workaround. First, you write a custom database query which is known to perform well and populates a list ofids. Then youdelegateToSchemathe ids toneo4j-graphql-js. If the results are not in order, you could still reorder the results based on the order of your pre-populated ids, e.g. just before youreturnin your custom resolver.TODO
node_modulesfolderneo4j-graphql-jsinaccessible to the client (e.g. because of authorization)