Skip to content

Repository files navigation

DynQL

Build Statusnpm Versionnpm bundle size (minified)MaintainabilityTest Coveragenpm License

A simple library to dynamically resolve GraphQL Fragments

Installation

npm i dynql
# Or Yarn
yarn add dynql

Usage

Simply create a new store instance, save fragments into it and resolve them from your query:

import{FragmentStore}from'dynql';conststore=newFragmentStore();// Manually register your fragmentstore.registerFragment("simple",`fragment simple on Something { field1 field2 ...some_other field3 { ...yet_another }}`);// Automatically registers all fragmentsstore.autoRegisterFragment(`fragment some_other on CoolElement { value1 value2 nested { ...yet_another }}fragment yet_another on AdvancedValue { hell_world}`);// Resolve the required fragments for the queryconstresolvedFragments=store.resolve(`query { someResolver { anElement { ...simple } } }`);// resolvedFragments[`fragment simple on Something { field1 field2}`,`fragment some_other on CoolElement { value1 value2 nested { ...yet_another }}`,`fragment yet_another on AdvancedValue { hell_world}`]

Nested Example

In this example, it shows how fragments can reference other fragments which are in the store which also get resolved dynamically.

store.registerFragment("objectA",`fragment objectA on Something { field1 field2 ...objectB}`);store.registerFragment("objectB",`fragment objectB on SomethingElse { field3 field4}`);store.registerFragment("objectC",`fragment objectC on Unused { unusedField unusedFragment }`);store.resolve(`query { someResolver { anElement { ...simple } } }`);// Returns["fragment objectA on Something {field1field2 ...objectB}","fragment objectB on SomethingElse {field3field4}"]

About

A simple library to dynamically resolve GraphQL Fragments

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages