gft

graphql-fields-to-relations

Resolve your graphql fields to (MikroOrm) relations

Showing:

Popularity

Downloads/wk

384

GitHub Stars

28

Maintenance

Last Commit

15d ago

Contributors

2

Package

Dependencies

2

License

MIT

Type Definitions

Built-In

Tree-Shakeable

No?

Categories

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"
]

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial