graphql-import-macro is a utility library designed to parse and expand GraphQL import statements within GraphQL document definitions. It aims to provide a reference implementation for a relatively standardized GraphQL import syntax, emphasizing minimal dependencies. The library enables the DRY principle in GraphQL documents by allowing modularization and reuse of schema fragments. The current stable version is 1.0.0, released in April 2020. There have been no subsequent updates, suggesting it is no longer actively maintained. Its primary differentiator is its focus on being a lightweight, standalone parser for tools that need to support GraphQL imports, without aiming to become part of the official GraphQL specification.
npm install graphql-import-macroVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to parse a GraphQL document, process its imports, and log the resolved AST.
Thoroughly test with your specific `graphql` package version. Consider alternative solutions for GraphQL imports if compatibility issues arise with newer GraphQL versions.
Ensure all tools in your GraphQL workflow (e.g., build tools, linters, servers) are aware of and correctly process the expanded GraphQL documents, or implement custom pre-processing steps.
Always instantiate `graphql.Source` with both the content string and the file path (e.g., `new Source(content, path)`).
Ensure `graphql.Source` is created with both the GraphQL content and its originating file path: `new Source(content, 'path/to/file.graphql')`.
Verify that `graphql-import-macro` is installed (`npm install graphql-import-macro`) and that you are using the correct named import: `import { processDocumentImports } from 'graphql-import-macro';`.Install the `graphql` package: `npm install graphql` (or `yarn add graphql`).