{"id":16398104,"url":"https://github.com/hebilicious/ungraphql-parse-info","last_synced_at":"2026-05-15T11:33:01.705Z","repository":{"id":227519228,"uuid":"771642279","full_name":"Hebilicious/ungraphql-parse-info","owner":"Hebilicious","description":"An ESM, JSR published, edge compatible GraphQL info parser based on graphql-parse-resolve-info","archived":false,"fork":false,"pushed_at":"2024-03-13T18:39:51.000Z","size":32,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-04T20:13:49.583Z","etag":null,"topics":["graphql","parse","parse-info"],"latest_commit_sha":null,"homepage":"https://jsr.io/@hebilicious/ungraphql-parse-info","language":"TypeScript","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/Hebilicious.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":["Hebilicious"]}},"created_at":"2024-03-13T17:15:23.000Z","updated_at":"2024-03-20T02:51:49.000Z","dependencies_parsed_at":"2024-03-13T18:58:32.152Z","dependency_job_id":"931f3574-72fc-44df-9b07-f36deba15715","html_url":"https://github.com/Hebilicious/ungraphql-parse-info","commit_stats":null,"previous_names":["hebilicious/ungraphql-parse-info"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hebilicious%2Fungraphql-parse-info","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hebilicious%2Fungraphql-parse-info/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hebilicious%2Fungraphql-parse-info/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hebilicious%2Fungraphql-parse-info/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hebilicious","download_url":"https://codeload.github.com/Hebilicious/ungraphql-parse-info/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240294734,"owners_count":19778754,"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","parse","parse-info"],"created_at":"2024-10-11T05:11:52.144Z","updated_at":"2026-05-15T11:32:56.679Z","avatar_url":"https://github.com/Hebilicious.png","language":"TypeScript","funding_links":["https://github.com/sponsors/Hebilicious"],"categories":[],"sub_categories":[],"readme":"# ungraphql-parse-info\n\n\u003e Original work by Benjie Gillam : https://www.npmjs.com/package/graphql-parse-resolve-info\n\nAn ESM, edge compatible, GraphQL info parser based on `graphql-parse-resolve-info`.\n\nParses a `GraphQLResolveInfo` object into a tree of the fields that are being\nrequested to enable optimisations to your GraphQL schema (e.g. to determine\nwhich fields are required from the backend).\n\nUseful for optimising your GraphQL resolvers by allowing them to look ahead in\nthe request, reducing the number of SQL queries or HTTP requests required to\ncomplete the GraphQL request.\n\nAlso provides a quick way to get the alias of the current field being resolved.\n\n## API\n\n### `parseResolveInfo(resolveInfo)`\n\nAlias: `parse`\n\nGets the tree of subfields of the current field that is being requested,\nreturning the following properties (recursively):\n\n- `name`: the name of the GraphQL field\n- `alias`: the alias this GraphQL field has been requested as, or if no alias was specified then the `name`\n- `args`: the arguments this field was called with; at the root level this\n  will be equivalent to the `args` that the `resolve(data, args, context, resolveInfo) {}` method receives, at deeper levels this allows you to get the\n  `args` for the nested fields without waiting for their resolvers to be called.\n- `fieldsByTypeName`: an object keyed by GraphQL object type names, where the\n  values are another object keyed by the aliases of the fields requested with\n  values of the same format as the root level (i.e. `{alias, name, args, fieldsByTypeName}`); see below for an example\n\nNote that because GraphQL supports interfaces a resolver may return items of\ndifferent types. For this reason, we key the fields by the GraphQL type name of\nthe various fragments that were requested into the `fieldsByTypeName` field.\n\nOnce you know which specific type the result is going to be, you can then use\nthis type (and its interfaces) to determine which sub-fields were requested -\nwe provide a `simplifyParsedResolveInfoFragmentWithType` helper to aid you with\nthis. In many cases you will know what type the result will be (because it can\nonly be one type) so you will probably use this helper heavily.\n\nExample usage:\n\n```ts\nimport {\n  parseResolveInfo,\n  simplifyParsedResolveInfoFragmentWithType\n} from '@hebilicious/ungraphql-parse-resolve-info'\n// or import { parseResolveInfo, simplifyParsedResolveInfoFragmentWithType } from 'graphql-parse-resolve-info';\n\nnew GraphQLObjectType({\n  name: ...\n  fields: {\n    ...\n    foo: {\n      type: new GraphQLNonNull(ComplexType),\n      resolve(data, args, context, resolveInfo) {\n        const parsedResolveInfoFragment = parseResolveInfo(resolveInfo);\n        const { fields } = simplifyParsedResolveInfoFragmentWithType(\n          parsedResolveInfoFragment,\n          ComplexType\n        );\n        console.dir(fields);\n        ...\n      }\n    }\n  }\n});\n```\n\n### `simplifyParsedResolveInfoFragmentWithType(parsedResolveInfoFragment, ReturnType)`\n\nAlias: `simplify`\n\nGiven an object of the form returned by `parseResolveInfo(...)` (which can be\nthe root-level instance, or it could be one of the nested subfields) and a\nGraphQL type this method will return an object of the form above, with an\nadditional field `fields` which only contains the fields compatible with the\nspecified `ReturnType`.\n\nOr, in other words, this simplifies the `fieldsByTypeName` to an object of only\nthe fields compatible with `ReturnType`.\n\nExample usage:\n\n```ts\nimport {\n  parseResolveInfo,\n  simplifyParsedResolveInfoFragmentWithType\n} from '@hebilicious/ungraphql-parse-resolve-info'\n\nnew GraphQLObjectType({\n  name: ...\n  fields: {\n    ...\n    foo: {\n      type: new GraphQLNonNull(ComplexType),\n      resolve(data, args, context, resolveInfo) {\n        const parsedResolveInfoFragment = parseResolveInfo(resolveInfo);\n\n        const { fields } = simplifyParsedResolveInfoFragmentWithType(\n          parsedResolveInfoFragment,\n          ComplexType\n        );\n        ...\n      }\n    }\n  }\n});\n```\n\n### `getAliasFromResolveInfo(resolveInfo)`\n\nAlias: `getAlias`\n\nReturns the alias of the field being requested (or, if no alias was specified,\nthen the name of the field).\n\nExample:\n\n```ts\nimport { getAliasFromResolveInfo } from '@hebilicious/ungraphql-parse-resolve-info'\n\nnew GraphQLObjectType({\n  name: ...\n  fields: {\n    ...\n    foo: {\n      type: new GraphQLNonNull(GraphQLString),\n      resolve(data, args, context, resolveInfo) {\n        const alias = getAliasFromResolveInfo(resolveInfo);\n        return alias;\n      }\n    }\n  }\n});\n```\n\n## Example\n\nFor the following GraphQL query:\n\n```graphql\n{\n  allPosts {\n    edges {\n      cursor\n      node {\n        ...PostDetails\n        author: personByAuthorId {\n          firstPost {\n            ...PostDetails\n          }\n          friends {\n            nodes {\n              ...PersonDetails\n            }\n            totalCount\n            pageInfo {\n              startCursor\n            }\n          }\n        }\n      }\n    }\n  }\n}\n\nfragment PersonDetails on Person {\n  id\n  name\n  firstName\n}\n\nfragment PostDetails on Post {\n  id\n  headline\n  headlineTrimmed\n  author: personByAuthorId {\n    ...PersonDetails\n  }\n}\n```\n\nThe following resolver in the `allPosts` field:\n\n```js\nconst Query = new GraphQLObjectType({\n  name: \"Query\",\n  fields: {\n    allPosts: {\n      type: new GraphQLNonNull(PostsConnection),\n      resolve(parent, args, context, resolveInfo) {\n        const parsedResolveInfoFragment = parseResolveInfo(resolveInfo);\n        const simplifiedFragment = simplifyParsedResolveInfoFragmentWithType(\n          parsedResolveInfoFragment,\n          resolveInfo.returnType\n        );\n        // ...\n      },\n    },\n\n    // ...\n  },\n});\n```\n\nhas `parsedResolveInfoFragment`:\n\n```js\n{ alias: 'allPosts',\n  name: 'allPosts',\n  args: {},\n  fieldsByTypeName:\n   { PostsConnection:\n      { edges:\n         { alias: 'edges',\n           name: 'edges',\n           args: {},\n           fieldsByTypeName:\n            { PostsEdge:\n               { cursor:\n                  { alias: 'cursor',\n                    name: 'cursor',\n                    args: {},\n                    fieldsByTypeName: {} },\n                 node:\n                  { alias: 'node',\n                    name: 'node',\n                    args: {},\n                    fieldsByTypeName:\n                     { Post:\n                        { id: { alias: 'id', name: 'id', args: {}, fieldsByTypeName: {} },\n                          headline:\n                           { alias: 'headline',\n                             name: 'headline',\n                             args: {},\n                             fieldsByTypeName: {} },\n                          headlineTrimmed:\n                           { alias: 'headlineTrimmed',\n                             name: 'headlineTrimmed',\n                             args: {},\n                             fieldsByTypeName: {} },\n                          author:\n                           { alias: 'author',\n                             name: 'personByAuthorId',\n                             args: {},\n                             fieldsByTypeName:\n                              { Person:\n                                 { id: { alias: 'id', name: 'id', args: {}, fieldsByTypeName: {} },\n                                   name: { alias: 'name', name: 'name', args: {}, fieldsByTypeName: {} },\n                                   firstName:\n                                    { alias: 'firstName',\n                                      name: 'firstName',\n                                      args: {},\n                                      fieldsByTypeName: {} },\n                                   firstPost:\n                                    { alias: 'firstPost',\n                                      name: 'firstPost',\n                                      args: {},\n                                      fieldsByTypeName:\n                                       { Post:\n                                          { id: { alias: 'id', name: 'id', args: {}, fieldsByTypeName: {} },\n                                            headline:\n                                             { alias: 'headline',\n                                               name: 'headline',\n                                               args: {},\n                                               fieldsByTypeName: {} },\n                                            headlineTrimmed:\n                                             { alias: 'headlineTrimmed',\n                                               name: 'headlineTrimmed',\n                                               args: {},\n                                               fieldsByTypeName: {} },\n                                            author:\n                                             { alias: 'author',\n                                               name: 'personByAuthorId',\n                                               args: {},\n                                               fieldsByTypeName:\n                                                { Person:\n                                                   { id: { alias: 'id', name: 'id', args: {}, fieldsByTypeName: {} },\n                                                     name: { alias: 'name', name: 'name', args: {}, fieldsByTypeName: {} },\n                                                     firstName:\n                                                      { alias: 'firstName',\n                                                        name: 'firstName',\n                                                        args: {},\n                                                        fieldsByTypeName: {} } } } } } } },\n                                   friends:\n                                    { alias: 'friends',\n                                      name: 'friends',\n                                      args: {},\n                                      fieldsByTypeName:\n                                       { PeopleConnection:\n                                          { nodes:\n                                             { alias: 'nodes',\n                                               name: 'nodes',\n                                               args: {},\n                                               fieldsByTypeName:\n                                                { Person:\n                                                   { id: { alias: 'id', name: 'id', args: {}, fieldsByTypeName: {} },\n                                                     name: { alias: 'name', name: 'name', args: {}, fieldsByTypeName: {} },\n                                                     firstName:\n                                                      { alias: 'firstName',\n                                                        name: 'firstName',\n                                                        args: {},\n                                                        fieldsByTypeName: {} } } } },\n                                            totalCount:\n                                             { alias: 'totalCount',\n                                               name: 'totalCount',\n                                               args: {},\n                                               fieldsByTypeName: {} },\n                                            pageInfo:\n                                             { alias: 'pageInfo',\n                                               name: 'pageInfo',\n                                               args: {},\n                                               fieldsByTypeName:\n                                                { PageInfo:\n                                                   { startCursor:\n                                                      { alias: 'startCursor',\n                                                        name: 'startCursor',\n                                                        args: {},\n                                                        fieldsByTypeName: {} } } } } } } } } } } } } } } } } } },\n```\n\nand the simplified `simplifiedFragment` is the same as\n`parsedResolveInfoFragment`, but with the additional root-level property\n`fields` which compresses the root-level property `fieldsByTypeName` to a\nsingle-level object containing only the fields compatible with\n`resolveInfo.returnType` (in this case: only `edges`):\n\n```graphql\n{ alias: 'allPosts',\n  name: 'allPosts',\n  args: {},\n  fieldsByTypeName:\n\t\t...as before...\n  fields:\n   { edges:\n      { alias: 'edges',\n        name: 'edges',\n        args: {},\n        fieldsByTypeName:\n           ...as before...\n```\n\n## Thanks\n\nThis project was originally based on https://www.npmjs.com/package/graphql-parse-resolve-info, which itself is based on https://github.com/tjmehta/graphql-parse-fields, but has evolved a lot since then.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhebilicious%2Fungraphql-parse-info","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhebilicious%2Fungraphql-parse-info","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhebilicious%2Fungraphql-parse-info/lists"}