1.0.8 • Published 2 years ago

gql-pathify v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

gql-pathify

A lightweight + simple package for translating graphql requests into an array of paths to the nodes.

It won't add fields multiple times that gql will merge when resolving.

Eg:

query {
    a {
        a
        b
    }
    ...QueryFragment
}

fragment QueryFragment on RootQueryType {
    a {
        b 
        c
    }
}

will get translated to:

[
    'query',
    'query.a',
    'query.a.a',
    'query.a.b',
    'query.a.c',
]

When a field is aliased though, gql will resolve that multiple times, so its added multiple times.

EG:

query {
    a {
        a
        b
    }
    ...QueryFragment
}

fragment QueryFragment on RootQueryType {
    b: a {
        b
        c
    }
}

will be translated to

[
    'query',
    'query.a',
    'query.a.a',
    'query.a.b',
    'query.a',
    'query.a.b',
    'query.a.c',
]

Features:

  • Handles Inline fragments (recursively)
  • Handles normal Fragments (recursively)
  • Handles aliases
  • Returns the paths as many times as they are resolved - a field's path will only be added as much as it will be resolved.
  • 0 dependencies
  • Enforces a maximum field depth (handy if you don't want people querying too much data)
  • Enforces a maximum fragment depth (mostly since its recursive)

TODO:

  • Consider supporting skip directives.
1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago