quave:resolvers
quave:resolvers
is a Meteor package that receives a defintion and generates resolvers.
Why
We don't want to write the same resolvers all the time, for example, to list data, to get one specific record by id, to update data, etc. Then we have these common resolvers defined automatically.
We believe we are not reinventing the wheel in this package but what we are doing is like putting together the wheels in the vehicle :).
Installation
meteor add quave:resolvers
Usage
You will get automatically resolvers and methods in your collection.
resolvable
Methods:
save(input)
: saves or update your data into a document.erase(_id)
: removes your data using the _id.
You can apply this resolvable
composer in your collection using quave:collections
or manually to add new methods to your collection.
1import { createCollection } from 'meteor/quave:collections'; 2import { resolvable } from 'meteor/quave:resolvers'; 3 4import { PlayerSchema, PlayerDefinition } from './PlayersDefinitions'; 5 6export const PlayersCollection = createCollection({ 7 name: PlayerDefinition.pluralNameCamelCase, 8 definition: PlayerDefinition, 9 schema: PlayerSchema, 10 composers: [resolvable], 11});
GraphQL
Resolvers and Schema (using Player
as example but the names will be based in your definition):
type Query { player(_id: ID!): Player players: [Player] } type Mutation { savePlayer(player: PlayerInput!): Player erasePlayer(_id: ID!): Player }
You create your resolvers using the definition and the collection together as you can see below.
1import { startGraphQLServer } from 'meteor/quave:graphql'; 2 3import { createResolvers } from 'meteor/quave:resolvers'; 4 5import { DateTimeResolver } from 'meteor/quave:custom-type-date-time/DateTimeResolver'; 6import { DateTimeDefinition } from 'meteor/quave:custom-type-date-time/DateTimeDefinition'; 7import { PlayerPositionDefinition } from '../imports/players/PlayerPositionEnum'; 8import { PlayersCollection } from '../imports/players/PlayersCollection'; 9import { PlayerDefinition } from '../imports/players/PlayersDefinitions'; 10 11startGraphQLServer({ 12 typeDefs: [ 13 DateTimeDefinition, 14 PlayerPositionDefinition.toGraphQL(), 15 PlayerDefinition.toGraphQL(), 16 ], 17 resolvers: [ 18 DateTimeResolver, 19 createResolvers({ 20 definition: PlayerDefinition, 21 collection: PlayersCollection, 22 }), 23 ], 24}); 25
License
MIT