evenchange4 / graphql.macro

Compile GraphQL AST at build-time with babel-plugin-macros.
MIT License
239 stars 21 forks source link

Support sharing fragments #117

Open davidmwhynot opened 3 years ago

davidmwhynot commented 3 years ago

It would be great if there was a way to either grab just specific operations from a specific file, or, alternatively, supply a path to a file containing fragments field as an argument to loader. i.e.

export const storesQuery: DocumentNode<
    Operations.StoresQuery,
    Operations.StoresQueryVariables
> = loader('../queries/stores.graphql', {
        fragments: '../fragments.graphql'
});

or something to that affect.

I'm guessing that this approach would be much simpler to implement than being able to have all of the queries and operations in a single file. I'm not an expert, but based on looking at what happens when you console.log a file that is loaded in with multiple operations, you would have to somehow extract the relevant properties/fields from the AST and make them available after parsing the file.