Skip to content

Instantly share code, notes, and snippets.

@govorov
Last active October 14, 2017 01:47
Show Gist options
  • Select an option

  • Save govorov/e51db1858a0ac9ff95e584763666b3b5 to your computer and use it in GitHub Desktop.

Select an option

Save govorov/e51db1858a0ac9ff95e584763666b3b5 to your computer and use it in GitHub Desktop.
//
// graphql/resolvers.ts
//
import { cardResolver } from 'graphql/resolvers/card';
import { cardsResolver } from 'graphql/resolvers/cards';
export const resolvers = {
Query: {
...cardsResolver,
...cardResolver,
},
};
//
// graphql/resolvers/card.ts
//
import { getRepository } from 'typeorm';
import { Card } from 'entities/card';
export const cardResolver = {
async card(obj, { id }, context, info) {
const repository = getRepository(Card);
return await repository.findOne({ id });
}
};
//
// graphql/resolvets/cards.ts
//
import { getRepository } from 'typeorm';
import { Card } from 'entities/card';
export const cardsResolver = {
async cards() {
const repository = getRepository(Card);
return await repository.find();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment