{"_id":"graphql-import-macro","_rev":"2738044","name":"graphql-import-macro","description":"A simple parser and expander for GraphQL imports","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"npm:squirly","email":""}],"time":{"modified":"2022-01-28T15:50:49.000Z","created":"2020-04-21T07:56:55.283Z","1.0.0":"2020-04-21T07:56:55.283Z"},"users":{},"author":{"name":"Tyler Jones","email":"tyler@squirly.ca"},"repository":{"type":"git","url":"git+https://github.com/squirly/graphql-import-macro.git"},"versions":{"1.0.0":{"name":"graphql-import-macro","version":"1.0.0","description":"A simple parser and expander for GraphQL imports","main":"index.js","repository":{"type":"git","url":"git+https://github.com/squirly/graphql-import-macro.git"},"keywords":["graphql"],"author":{"name":"Tyler Jones","email":"tyler@squirly.ca"},"license":"MIT","bugs":{"url":"https://github.com/squirly/graphql-import-macro/issues"},"homepage":"https://github.com/squirly/graphql-import-macro#readme","dependencies":{"graphql":"^15.0.0"},"_id":"graphql-import-macro@1.0.0","_nodeVersion":"12.16.2","_npmVersion":"6.14.4","dist":{"shasum":"987c62bdebf5f26c77bb0e67a5f67afd7d0b5f42","size":7494,"noattachment":false,"key":"/graphql-import-macro/-/graphql-import-macro-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/graphql-import-macro/download/graphql-import-macro-1.0.0.tgz"},"maintainers":[{"name":"npm:squirly","email":""}],"_npmUser":{"name":"squirly","email":"tylerjones64@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-import-macro_1.0.0_1587455815177_0.6875981352560179"},"_hasShrinkwrap":false,"publish_time":1587455815283,"_cnpm_publish_time":1587455815283}},"readme":"# graphql-import-macro\n\n[![license](https://img.shields.io/github/license/squirly/graphql-import-macro.svg)](LICENSE)\n[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n\nA parser and expander for GraphQL imports, with minimal dependencies.\n\n## Table of Contents\n\n-   [Background](#background)\n-   [Install](#install)\n-   [Usage](#usage)\n-   [API](#api)\n-   [Contributing](#contributing)\n-   [License](#license)\n\n## Background\n\nThere is a relatively standardized syntax for imports in GraphQL. This library\naims to provide a reference implementation with minimal dependencies.\n\nThe primary target audience of this library are tools that want to support a\nstandardized GraphQL import.\n\n### Goals\n\n-   Provide reusabily and allow the DRY principal in GraphQL. Primarily focusing\n    on\n    [GraphQL Document](https://spec.graphql.org/June2018/#sec-Language.Document).\n\n### Non-goals\n\n-   Becoming part of the GraphQL spec.\n    -   The GraphQL spec defines a query language, much like SQL and does not\n        need the complexities of imports.\n        https://github.com/graphql/graphql-spec/issues/343#issuecomment-426153002\n\n## Install\n\n```bash\nnpm install graphql-import-macro\n```\n\n## Usage\n\n```js\nimport {parse, Source} from \"graphql\";\nimport {processDocumentImports} from \"graphql-import-macro\";\n\nconst ast = parse(new Source(content, path));\n\nconst resolvedAst = await processDocumentImports(ast);\n\nconsole.log(resolvedAst);\n```\n\n### Supported Syntax\n\nWhitespace is ignored, except where necessary to parse tokens (`import`, `*`,\n`,`, and `from`).\n\n#### Macro Matcher\n\nAll matches of the following RegEX will be treated as imports:\n\n```regex\n#\\s*import\\s+(.+)\\s*(?:\\n|\\r(?!\\n)|\\r\\n|$)\n```\n\n[![Regular expression visualization](https://www.debuggex.com/i/YYSM4MAysi5rXOoV.png)](https://www.debuggex.com/r/YYSM4MAysi5rXOoV)\n\nSee:\n\n-   [GraphQL Comments](https://spec.graphql.org/June2018/#sec-Comments)\n-   [GraphQL Line Terminator](https://spec.graphql.org/June2018/#LineTerminator)\n\n#### Supported Import Formats\n\nImport all:\n\n```graphql\n#import 'path.graphql'\n#import * from 'path.graphql'\n```\n\nNamed Import:\n\n```graphql\n#import A, B, C from 'path.graphql'\n```\n\nGroup 1 from all imports will be matched against the following RegEx\n\n```regex\n^(?:(?:\\*|((?:[_A-Za-z][_0-9A-Za-z]+\\s*,\\s*)*[_A-Za-z][_0-9A-Za-z]+))\\s+from\\s+|)?(?:'(.+)'|\"(.+)\")$\n```\n\n[![Regular expression visualization](https://www.debuggex.com/i/CNTDhwl2OIBZoiQO.png)](https://www.debuggex.com/r/CNTDhwl2OIBZoiQO)\n\n-   Group 1 is used to determine if all or some of the imported file should be\n    included.\n-   Group 2 & 3 are used to get the relative file path.\n\n## API\n\n### Documents\n\nEach AST `DocumentNode` must be created from a `Source` instantiated with at\nleast two parameters. This ensures that correct path information is attached.\n\n```js\nimport {parse, Source} from \"graphql\";\n\nconst ast = parse(new Source(content, path));\n```\n\n#### `processDocumentImports(ast, importResolver?)`\n\nGiven an AST and optional resolver, parses imports and expands them recursively.\n\nThe loader argument can be passed to use custom loading logic and must conform\nto the following:\n\n```ts\nimport type {DocumentNode} from \"graphql\";\n\nlet importResolver: (from: string, to: string) => Promise<DocumentNode>;\n```\n\n## Contributing\n\nPRs accepted. Commit messages must conform to the default\n[Semantic Release format](https://github.com/semantic-release/semantic-release#commit-message-format).\n\nSmall note: If editing the Readme, please conform to the\n[standard-readme](https://github.com/RichardLitt/standard-readme) specification.\n\n## License\n\n[MIT © Tyler David Jones](../LICENSE)\n","_attachments":{},"homepage":"https://github.com/squirly/graphql-import-macro#readme","bugs":{"url":"https://github.com/squirly/graphql-import-macro/issues"},"license":"MIT"}