{"id":13433222,"url":"https://github.com/anvilco/graphql-introspection-tools","last_synced_at":"2025-04-15T23:15:46.359Z","repository":{"id":39852533,"uuid":"466233843","full_name":"anvilco/graphql-introspection-tools","owner":"anvilco","description":"A library to query and manipulate GraphQL Introspection Query results in some useful ways.","archived":false,"fork":false,"pushed_at":"2024-01-29T21:54:48.000Z","size":868,"stargazers_count":34,"open_issues_count":7,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-15T23:15:43.463Z","etag":null,"topics":["graphql","javascript","nodejs"],"latest_commit_sha":null,"homepage":"https://www.useanvil.com/blog/engineering/manipulate-graphql-schemas-with-microfiber","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anvilco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-04T18:41:53.000Z","updated_at":"2025-01-22T20:47:51.000Z","dependencies_parsed_at":"2023-02-16T12:01:28.366Z","dependency_job_id":"544f01a6-f9c6-45ad-9e75-2b9415cef766","html_url":"https://github.com/anvilco/graphql-introspection-tools","commit_stats":{"total_commits":79,"total_committers":4,"mean_commits":19.75,"dds":0.4683544303797469,"last_synced_commit":"daf94e764d843988bd9661ec8f12feb345a6f5ca"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvilco%2Fgraphql-introspection-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvilco%2Fgraphql-introspection-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvilco%2Fgraphql-introspection-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvilco%2Fgraphql-introspection-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anvilco","download_url":"https://codeload.github.com/anvilco/graphql-introspection-tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249167457,"owners_count":21223508,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","javascript","nodejs"],"created_at":"2024-07-31T02:01:22.680Z","updated_at":"2025-04-15T23:15:46.331Z","avatar_url":"https://github.com/anvilco.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Implementations"],"sub_categories":["JavaScript/TypeScript"],"readme":"\u003ca href=\"https://www.useanvil.com\"\u003e\u003cimg src=\"/static/anvil.png\" width=\"50\"\u003e\u003c/a\u003e\n\n# Microfiber - A.K.A. GraphQL Introspection Tools\n\n[![npm][npm]][npm-url]\n[![downloads][npm-downloads]][npm-url]\n\n\u003ca href=\"https://www.useanvil.com/docs\"\u003e\u003cimg src=\"/static/microfiber.png\" width=\"500\"\u003e\u003c/a\u003e\n\nA library to query and manipulate GraphQL Introspection Query results in some useful ways. What ways you ask?\n\nHow about:\n- Digging through your Introspection Query Results for a specific Query, Mutation, Type, Field, Argument or Subscription.\n- Removing a specific Query, Mutation, Type, Field/InputField, Argument or Subscription from your Introspection Query Results.\n- Removing Queries, Mutations, Fields/InputFields or Arguments that refer to Type that does not exist in - or has been removed from - your Introspection Query Results.\n\nYay!\n\nIt's called `microfiber` because it is heavily used to do the cleaning and manipulation in [SpectaQL][spectaql]...it *cleans* the *spectacles*, get it?!\n\nBut, we also wanted to have a more intuitive, literal name so that people could find it. Hence it's also known as `@anvilco/graphql-introspection-tools`.\n\n---\n\n**Repository sponsored by [Anvil](www.useanvil.com/developers)**\n\n![Horizontal Lockupblack](https://user-images.githubusercontent.com/293079/169453889-ae211c6c-7634-4ccd-8ca9-8970c2621b6f.png#gh-light-mode-only)\n![Horizontal Lockup copywhite](https://user-images.githubusercontent.com/293079/169453892-895f637b-4633-4a14-b997-960c9e17579b.png#gh-dark-mode-only)\n\nAnvil provides easy APIs for all things paperwork.\n\n1. [PDF filling API](https://www.useanvil.com/products/pdf-filling-api/) - fill out a PDF template with a web request and structured JSON data.\n2. [PDF generation API](https://www.useanvil.com/products/pdf-generation-api/) - send markdown or HTML and Anvil will render it to a PDF.\n3. [Etch e-sign with API](https://www.useanvil.com/products/etch/) - customizable, embeddable, e-signature platform with an API to control the signing process end-to-end.\n4. [Anvil Workflows (w/ API)](https://www.useanvil.com/products/workflows/) - Webforms + PDF + e-sign with a powerful no-code builder. Easily collect structured data, generate PDFs, and request signatures.\n\nLearn more on our [Anvil developer page](https://www.useanvil.com/developers/).\n\n---\n\n## Getting Started\n\n1. Install `microfiber`  \n```sh\nnpm install microfiber\n# OR\nyarn add microfiber\n```\n\n2. Clean your GraphQL Introspection Query Results\n```node\nimport { Microfiber } from 'microfiber'\n\nconst introspectionQueryResults = {...}\n\nconst microfiber = new Microfiber(introspectionQueryResults)\n\n// ...do some things to your schema with `microfiber`\n\nconst cleanedIntrospectonQueryResults = microfiber.getResponse()\n\n// ...do something with your cleaned Introspection Query Results.\n```\n\n## Usage\n\n### class Microfiber\n\nMost of the useful stuff in this library is done through creating a new Microfiber class instance with your Introspection Query Results, and querying or manipulating it via that instance. Here are most of the interesting bits to know about class behavior.\n\n---\n#### constructor\n```node\nconst introspectionQueryResponse = {...}\n// Here are the publicly supported options and their sane defaults:\nconst options = {\n  // Some GraphQL implementations have non-standard Query, Mutation and/or Subscription\n  // type names. This option will fix them if they're messed up in the Introspection Query\n  // Results\n  fixQueryAndMutationAndSubscriptionTypes: true,\n\n  // Remove Types that are not referenced anywhere by anything\n  removeUnusedTypes: true,\n\n  // Remove things whose Types are not found due to being removed\n  removeFieldsWithMissingTypes: true,\n  removeArgsWithMissingTypes: true,\n  removeInputFieldsWithMissingTypes: true,\n  removePossibleTypesOfMissingTypes: true,\n\n  // Remove all the types and things that are unreferenced immediately?\n  cleanupSchemaImmediately: true,  \n}\n\nconst microfiber = new Microfiber(introspectionQueryResponse, options)\n```\n---\n#### cleanSchema\nClean up the schema by removing:\n- Fields or Input Fields whose Type does not exist in the schema.\n- Args whose Type does not exist in the schema.\n- Possible Types in a Union that do not exist in the schema.\n- Queries or Mutations whose return Type does not exist in the schema.\n\nThis method is usually called after altering the schema in any way so as to not leave any dangling/orphaned things around the schema.\n```node\nmicrofiber.cleanSchema()\n```\n---\n#### getResponse\nGet out the Introspection Query Result that you have manipulated with Microfiber as an Object.\n```node\nconst cleanedResponse = microfiber.getResponse()\n```\n---\n#### getAllTypes\nGet all the Types from your schema as an Array of Objects. Supported options and their sane defaults are shown.\n```node\nconst allTypes = microfiber.getAllTypes({\n  // Include reserved GraphQL types?\n  includeReserved: false,\n  // Include the Query type?\n  includeQuery: false,\n  // Include the Mutation type?\n  includeMutation: false,\n  // Include the Subscription type?\n  includeSubscription: false,\n} = {})\n```\n---\n#### getType\nGet a specific Type from your schema. Supported params and their sane defaults are shown.\n```node\nconst type = microfiber.getType({ kind: 'OBJECT', name })\n```\n---\n#### getDirectives\nGet all the Directives from your schema.\n```node\nconst directives = microfiber.getDirectives()\n```\n---\n#### getDirective\nGet a specific Directive from your schema. Supported params and their sane defaults are shown.\n```node\nconst directive = microfiber.getDirective({ name })\n```\n---\n#### getQueryType\nGet the Query Type from your schema.\n```node\nconst queryType = microfiber.getQueryType()\n```\n---\n#### getQuery\nGet a specific Query from your schema.\n```node\nconst query = microfiber.getQuery({ name })\n```\n---\n#### getMutationType\nGet the Mutation Type from your schema.\n```node\nconst mutationType = microfiber.getMutationType()\n```\n---\n#### getMutation\nGet a specific Mutation from your schema.\n```node\nconst mutation = microfiber.getMutation({ name })\n```\n---\n#### getSubscriptionType\nGet the Subscription Type from your schema.\n```node\nconst subscriptionType = microfiber.getSubscription()\n```\n---\n#### getSubscription\nGet a specific Subscription from your schema.\n```node\nconst subscription = microfiber.getSubscription({ name })\n```\n---\n#### getField\nGet a specific Field from your schema. Supported params and their sane defaults are shown.\n```node\nconst field = microfiber.getField({ typeKind: 'OBJECT', typeName, fieldName })\n```\n---\n#### getInterfaceField\nGet a specific Field from an Interface in your schema. A convenience wrapper around `getField({ typeKind: 'INTERFACE', ...})`\n```node\nconst interfaceField = microfiber.getInterfaceField({ typeName, fieldName })\n```\n---\n#### getEnumValue\nGet a specific EnumValue from your schema. A convenience wrapper around `getField({ typeKind: 'ENUM', ...})`\n```node\nconst inputField = microfiber.getEnumValue({ typeName, fieldName })\n```\n---\n#### getInputField\nGet a specific InputField from your schema. A convenience wrapper around `getField({ typeKind: 'INPUT_OBJECT', ...})`\n```node\nconst inputField = microfiber.getInputField({ typeName, fieldName })\n```\n---\n#### getArg\nGet a specific Arg from your schema. Supported params and their sane defaults are shown.\n```node\nconst arg = microfiber.getArg({ typeKind: 'OBJECT', typeName, fieldName, argName })\n```\n---\n#### getDirectiveArg\nGet a specific Arg from a specifig Directive in your schema. Supported params and their sane defaults are shown.\n```node\nconst directiveArg = microfiber.getDirectiveArg({ directiveName, argName })\n```\n---\n#### removeDirective\nGet a specific Directive from your schema. Supported params and their sane defaults are shown.\n```node\nconst directiveArg = microfiber.removeDirective({\n  name,\n  // Clean up the schema afterwards?\n  cleanup = true,\n})\n```\n---\n#### removeType\nRemove a Type from your schema, and optionally the references to that Type elsewhere in your schema. Supported params and their sane defaults are shown.\n```node\nmicrofiber.removeType({\n  kind: 'OBJECT',\n  name,\n  // Clean up the schema afterwards?\n  cleanup: true,\n  // Remove occurances of this Type from other places?\n  removeFieldsOfType: constructorOptions.removeFieldsWithMissingTypes,\n  removeInputFieldsOfType: constructorOptions.removeInputFieldsWithMissingTypes,\n  removePossibleTypesOfType: constructorOptions.removePossibleTypesOfMissingTypes,\n  removeArgsOfType: constructorOptions.removeArgsWithMissingTypes,\n})\n```\n---\n#### removeField\nRemove a specific Field from a specific Type in your schema. Supported params and their sane defaults are shown.\n```node\nmicrofiber.removeField({\n  typeKind: 'OBJECT',\n  typeName,\n  fieldName,\n  // Clean up the schema afterwards?\n  cleanup: true,\n})\n```\n---\n#### removeInputField\nRemove a specific Input Field from a specific Input Object in your schema. Supported params and their sane defaults are shown.\n```node\nmicrofiber.removeInputField({\n  typeName,\n  fieldName,\n  // Clean up the schema afterwards?\n  cleanup: true,\n})\n```\n---\n#### removeArg\nRemove a specific Arg from a specific Field or Input Field in your schema. Supported params and their sane defaults are shown.\n```node\nmicrofiber.removeArg({\n  typeKind,\n  typeName,\n  fieldName,\n  argName,\n  // Clean up the schema afterwards?\n  cleanup: true,\n})\n```\n---\n#### removeEnumValue\nRemove a specifc Enum value from an Enum Type in your schema. Supported params are shown.\n```node\nmicrofiber.removeEnumValue({\n  // The name of the Enum Type\n  name,\n  // The Enum value you want to remove\n  value,\n})\n```\n---\n#### removePossibleType\nRemove a Possible Type from a specific Union Type in your schema. Supported params and sane defaults are shown.\n```node\nmicrofiber.removePossibleType({\n  // The name of the Union Type\n  typeName,\n  // The Kind of the possible Type you want to remove\n  possibleTypeKind,\n  // The name of the possible Type you want to remove\n  possibleTypeName,\n  // Clean up the schema afterwards?\n  cleanup: true,\n})\n```\n---\n#### removeQuery\nRemove a specific Query from your schema. Supported params and their sane defaults are shown.\n```node\nmicrofiber.removeQuery({\n  name,\n  // Clean up the schema afterwards?\n  cleanup: true,\n})\n```\n---\n#### removeMutation\nRemove a specific Mutation from your schema. Supported params and their sane defaults are shown.\n```node\nmicrofiber.removeMutation({\n  name,\n  // Clean up the schema afterwards?\n  cleanup: true,\n})\n```\n---\n#### removeSubscription\nRemove a specific Subscription from  your schema. Supported params and their sane defaults are shown.\n```node\nmicrofiber.removeSubscription({\n  name,\n  // Clean up the schema afterwards?\n  cleanup: true,\n})\n```\n\n### Other exports from this library\nThere are some other exports from this library, not just the `Microfiber` class. \n\n---\n#### KINDS\nAn Object containing all the GraphQL Kind values you may encounter.\n```node\nimport { KINDS } from 'microfiber'\n\nconsole.log(KINDS)\n\n// {\n//   SCALAR: 'SCALAR',\n//   OBJECT: 'OBJECT',\n//   INTERFACE: 'INTERFACE',\n//   UNION: 'UNION',\n//   ENUM: 'ENUM',\n//   INPUT_OBJECT: 'INPUT_OBJECT',\n//   LIST: 'LIST',\n//   NON_NULL: 'NON_NULL'\n// }\n```\n---\n#### typesAreSame\nA function that compares 2 types and determines if they have the same Kind and Name.\n```node\nimport { typesAreSame } from 'microfiber'\n\nconst typeA = { kind: 'OBJECT', name: 'Foo' }\nconst typeB = { kind: 'OBJECT', name: 'Bar' }\n\ntypesAreSame(typeA, typeB) // false\ntypesAreSame(typeA, typeA) // true\n```\n---\n#### digUnderlyingType\nA function that digs through any Non-Null and List nesting and returns the underlying Type.\n```node\nimport { digUnderlyingType } from 'microfiber'\n\nconst nonNullableString = {\n  name: null,\n  kind: 'NON_NULL',\n  ofType: {\n    name: null,\n    kind: 'LIST',\n    ofType: {\n      name: 'String',\n      kind: 'SCALAR',\n    }\n  }\n}\n\ndigUnderlyingType(nonNullableString) // { name: 'String', kind: 'SCALAR' }\n```\n---\n#### isReservedType\nA function that returns a Boolean indicating whether a Type is special GraphQL reserved Type.\n```node\nimport { isReservedType } from 'microfiber'\n\nconst myType = { name: 'Foo', ... }\nconst reservedType = { name: '__Foo', ... }\n\nisReservedType(myType) // false\nisReservedType(reservedType) // true\n```\n\n[npm]: https://badge.fury.io/js/microfiber.svg\n[npm-downloads]: https://img.shields.io/npm/dw/microfiber\n[npm-url]: https://www.npmjs.com/package/microfiber\n[spectaql]: https://github.com/anvilco/spectaql\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanvilco%2Fgraphql-introspection-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanvilco%2Fgraphql-introspection-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanvilco%2Fgraphql-introspection-tools/lists"}