{"_id":"graphql-import-macro","_rev":"1-906117c1ef0aa1edd415a75ad0488611","name":"graphql-import-macro","dist-tags":{"latest":"1.0.0"},"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":{"integrity":"sha512-YK4g6iP60H++MpP93tb0VwOg7aM5iIC0hdSQKTrEDANeLWf0KFAT9dwlBeMDrhY+jcW7qsAEDtaw58cgVnQXAw==","shasum":"987c62bdebf5f26c77bb0e67a5f67afd7d0b5f42","tarball":"https://registry.npmjs.org/graphql-import-macro/-/graphql-import-macro-1.0.0.tgz","fileCount":17,"unpackedSize":28761,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJenqdHCRA9TVsSAnZWagAAjIsP/0TK+JcuEXr8R8lcnYG8\nloRIVGIkFXL0ETJIJrpjw3KBfHz6vzR6LQten7N7n8pbCsVpRBYwez3iPesO\nJQUet0F9nhvERKc3IH8g7M8jYg22gbGq8NwlY/9R5SAHHdNAabL+i0on3fuy\n1pzkNKPMyuQivSDn412a+KzTa+qFll1FcMT7RYNLaUlw12jwKoixQXp8E0qT\n9waX+kTbvyEgG6c/Pto0wGDq5lW2wCEn9VWi0HFq4Kg3uJ9V6Jm+U+AlMUjG\nBu2Fn/L0bKf7EIbDAoJ/pX85JAnzRMxHwcyoLUQcE6ucTdU1giY8Kvwm3grv\nEmI0gzkAgMlmgQKVb/Qymw+ezx6TUnVB8LO+Eh5U61jAEmRLylRtOqJQAcLA\nECF2Ll8NB2vqQVolNIvIFpFadQugvEB0KmjP6vWYU00b7Qwk1joTycEpO12U\n8nQb/9dJjY1XsNpYULnPNddWPwIkL/1WobFl36eFNhaaoCwczc9GJBcAhkXZ\ndQZqqP+b9qDKikrjg3kF/RQ52/Iam2U69YGFSDpK2EwVDvzTk8Iqz/fQOWaW\noYd0Uelq6YA7rgKXHtvcdgCxY8riNUahKdBXYG3xJ0FTcLsvqbKV9tEYITIm\nv82XRrdJkUE7EBU72O8VK5t6zB0MiOYohLqxCjL9ztNX+/QH4H+Sw3djeNBQ\nRZjI\r\n=6Is0\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB/0xZql8MtLv6J0/fWPcvS6iHJqHwlJXggkYUqG3Vb/AiBK99MeUsOAyphABquZ9dW+QjG+CF4+Tng+5UX90flzTw=="}]},"maintainers":[{"name":"squirly","email":"tylerjones64@gmail.com"}],"_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}},"time":{"created":"2020-04-21T07:56:55.177Z","1.0.0":"2020-04-21T07:56:55.283Z","modified":"2022-05-04T02:59:56.672Z"},"maintainers":[{"name":"squirly","email":"tylerjones64@gmail.com"}],"description":"A simple parser and expander for GraphQL imports","homepage":"https://github.com/squirly/graphql-import-macro#readme","keywords":["graphql"],"repository":{"type":"git","url":"git+https://github.com/squirly/graphql-import-macro.git"},"author":{"name":"Tyler Jones","email":"tyler@squirly.ca"},"bugs":{"url":"https://github.com/squirly/graphql-import-macro/issues"},"license":"MIT","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","readmeFilename":"README.md"}