0.8.1 • Published 4 months ago

@graphql-ez/plugin-dataloader v0.8.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@graphql-ez/plugin-dataloader

Integration with DataLoader

Check https://www.graphql-ez.com for more information

Usage

This plugin adds an extra registerDataLoader in your ezApp, which will automatically add the specified dataloader in your GraphQL EZ Application Context.

This EZ Plugin uses @envelop/dataloader plugin seamlessly while you code

import { ezDataLoader } from '@graphql-ez/plugin-dataloader';

const ezApp = CreateApp({
  ez: {
    plugins: [
      ezDataLoader(),
      // ...
    ],
  },
  // ...
});

// ...

import type { InferDataLoader } from '@graphql-ez/plugin-dataloader';

const multiplierDataLoader = ezApp.registerDataLoader(
  'Multiplier',
  DataLoader =>
    new DataLoader<number, number>(async numbers => {
      return numbers.map(v => v * 2);
    })
);

// This snippet add automatically the type of your DataLoader in your EZContext
declare module 'graphql-ez' {
  interface EZContext extends InferDataLoader<typeof multiplierDataLoader> {}
}

// And if you are using https://www.graphql-ez.com/plugins/graphql-modules
// You could use it like this:

ezApp.registerModule(
  gql`
    extend type Query {
      multiply(n: Float!): Float!
    }
  `,
  {
    resolvers: {
      Query: {
        multiply(_root, { n }, { Multiplier }) {
          return Multiplier.load(n);
        },
      },
    },
  }
);
0.8.1

4 months ago

0.8.0

1 year ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.1.2

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago