Paginated GraphQL
A tool to create paginated Apollo GraphQL methods with Meteor Collections
yarn add paginated-graphql
Instructions
You need to use graphql-loader.
Once, after importing type definitions and resolvers import this package.
import {createApolloServer} from 'meteor/orionsoft:apollo'
import {makeExecutableSchema} from 'graphql-tools'
import {loadSchema, getSchema} from 'graphql-loader'
import typeDefs from './schema'
import resolvers from './resolvers'
import 'paginated-graphql'
loadSchema({typeDefs, resolvers})
const schema = makeExecutableSchema(getSchema())
createApolloServer({schema})
Defining the method
import query from 'paginated-graphql/lib/query'
const providers = query({
name: 'providers',
type: 'Provider',
params: 'filter: String'
})
export default `
type Query {
${providers}
}
`
Adding the resolver
import resolver from 'paginated-graphql/lib/resolver'
import Providers from 'api/collections/Providers'
const providers = resolver({
collection: Providers,
allowedSort: ['name', 'totalEarnings'],
fields: ['name'],
transformQuery (query, root, params, context) {
return query
}
})
export default {
Query: {
providers
}
}
Using $text
search
resolver({
collection: Transactions,
allowedSort: ['date', 'amount'],
fields: 'name',
search: true
})
const transactions = query({
name: 'transactions',
type: 'Transaction',
params: 'filter: String, search: String'
})
import setTextIndex from 'paginated-graphql/lib/setTextIndex'
setTextIndex(Transactions, {
name: 45,
comment: 5,
category: 1
})