JSPM

graphql-fields-to-relations

1.0.5
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1061
  • Score
    100M100P100Q105344F
  • License MIT

Resolve your graphql fields to (MikroOrm) relations

Package Exports

  • graphql-fields-to-relations

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphql-fields-to-relations) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

graphql-fields-to-relations

FieldsToRelations is a graphql helper that gets your relation string from graphql's input fields. This package was created for the MikroOrm Graphql Example.

NPM link

🔧 Usage

Install the package with yarn:

yarn add graphql-fields-to-relations

or with npm:

npm install graphql-fields-to-relations

And use it like so:

const fieldsToRelations = require('fieldsToRelations');

// in your resolver
const relations = fieldsToRelations(info);

🔍 Example

As an example, take following query:

query {
  getBoards {
    id name memberships {
      id user {
        email
      }
    }
    lists {
      items {
        id name list {
          id name
          board {
            id name
            memberships {
              id user {
                id email
              }
            }
          }
        }
      }
    }
  }
}

The helper will return the following relation string:

[
  "memberships",
  "memberships.user",
  "lists",
  "lists.items",
  "lists.items.list",
  "lists.items.list.board",
  "lists.items.list.board.memberships",
  "lists.items.list.board.memberships.user"
]