-
-
Notifications
You must be signed in to change notification settings - Fork 119
Support for GraphQL "extend" keyword #248
Comments
Hello @louisrli! Yes, I'm aware extensions are an integral part of GraphQLspec. However, they are barely used, as one could just add a new field on the original type (unless, and that may be your case, you're doing some kind of schema stitching). Given this lack of general usage (you're the first person who even talked about it), I've not prioritized it yet. If you're interested on it, I'd appreciate if you could open a PR implementing extensions (at least for your use case), so the library would grow! |
Thanks for the really fast response. Yes, I didn't want to add one schema mapping for each of my schemas (I'm not sure that would work either because the definitions are shared/overlapped among the schema files) For background, I've split my GraphQL files because the schema is pretty large (just for organization). In my JS server, it looks something like this, so it's merging them:
When attempting to use Artemis, I was trying to do some type of "stitching" like so:
Then in my
I'd agree that it's not worth your time to make it a priority. I think that it's possible to have a workaround, I will write a script that does something similar to what my server does, then try to see if it can reprint the GraphQL types to "stitch" them together. If I make it work, I'll write a solution here for anyone else who runs into the same thing :) |
I think something like this (but requiring use of a JS script outside of Flutter) would work: https://www.graphql-tools.com/docs/schema-merging/#print-merged-typedefs |
If implemented in Dart, this "script" could be the start of making Artemis support it! Maybe some kind of pre-process function (based on some new configuration on Artemis) that would join schemas, stitch them together (expanding extensions on their respective types), and use the the result into Artemis as if it was the original schema. |
@comigor I'm unsure how hard it is to join schemas in Dart, it depends on what's currently available in the GQL package. The script I ended up has most of its heavy lifting done by the JavaScript package I imagine merging GraphQL schemas is a somewhat non-trivial task, but I wonder if the Dart gql package has a similar functionality that could make it easier here. But don't take my word for it, I don't know the landscape at all. To be honest, I've written more YAML than Dart at this current point in time...but hopefully that'll change over the next few weeks when I start writing this app ;) For those who may check this and are willing to pop a Typescript/JS script somewhere, this is what I ended up using. import { mergeTypeDefs } from '@graphql-tools/merge';
import { loadFilesSync } from '@graphql-tools/load-files';
import { print } from 'graphql';
import * as fs from 'fs';
const typesArray = loadFilesSync('./src/schema', { extensions: ['graphql'] });
const merged = mergeTypeDefs(typesArray);
const printedTypeDefs = print(merged);
fs.writeFileSync('joined.graphql', printedTypeDefs); then I'll write a bash script to move it from the server folder into the mobile app folder as part of the generation process. |
Also, I'm not even sure if the extend keyword is supposed to be used in the same file as the original type (I think it's not). So this whole issue might be an artifact of me attempting to |
Before reporting a bug, please test the beta branch!
(beta branch has no changes to master at the time I'm reporting this)
Bug description
I have a GraphQL schema split into multiple files, also using the extend keyword, which admittedly seems to have pretty shaky support in general. Please let me know if I've made a mistake somehow in setting up Artemis here.
You would see an error for any type on an extended field, such as:
I've put together a small schema and query below to illustrate this.
Specs
Artemis version: 6.17.3
build.yaml:
Artemis output:
GraphQL schema:
GraphQL query:
The text was updated successfully, but these errors were encountered: