Skip to content

Commit

Permalink
Merge pull request #36 from syllogio/expose-list-propositions
Browse files Browse the repository at this point in the history
feat: expose propositions field which lists all propositions
  • Loading branch information
patrickocoffeyo committed Sep 20, 2019
2 parents 61bcd1f + fd56594 commit b82a074
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/graphql/resolvers/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('resolvers', () => {
},
"Query": Object {
"proposition": [Function],
"propositions": [Function],
},
}
`);
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import createProposition from './createProposition';
import proposition from './getProposition';
import propositions from './listPropositions';
import Proposition from './Proposition';
import setSupportedBy from './setSupportedBy';
import setSupports from './setSupports';
Expand All @@ -13,5 +14,6 @@ export default {
Proposition,
Query: {
proposition,
propositions,
},
};
40 changes: 40 additions & 0 deletions src/graphql/resolvers/listPropositions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
IProposition,
listPropositions as _listPropositions,
} from '../../lib/proposition';
import listPropositions from './listPropositions';

jest.mock('../../lib/proposition', () => ({
listPropositions: jest.fn(),
}));

const propositions = [
{
id: 0,
supportedBy: [1, 2],
supports: [],
text: 'Greeks are mortal',
},
{
id: 1,
supportedBy: [],
supports: [0],
text: 'All men are mortal',
},
{
id: 2,
supportedBy: [],
supports: [0],
text: 'Greeks are men',
},
];

(_listPropositions as jest.Mock<any>).mockImplementation(
async (): Promise<IProposition[]> => propositions
);

describe('Propositions', () => {
it('returns an array of propositions', async () => {
await expect(listPropositions()).resolves.toEqual(propositions);
});
});
8 changes: 8 additions & 0 deletions src/graphql/resolvers/listPropositions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { IProposition, listPropositions } from '../../lib/proposition';

/**
* GraphQL resolver for the propositions field.
*/
export default async function propositions(): Promise<IProposition[]> {
return listPropositions();
}
1 change: 1 addition & 0 deletions src/graphql/typeDefs/Root.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Query {
Get a proposition by its identifier.
"""
proposition(id: Int!): Proposition
propositions: [Proposition]
}

type Mutation {
Expand Down
1 change: 1 addition & 0 deletions src/graphql/typeDefs/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`typeDefs exports the GraphQL schema 1`] = `
type Query {
\\"\\"\\"Get a proposition by its identifier.\\"\\"\\"
proposition(id: Int!): Proposition
propositions: [Proposition]
}
type Mutation {
Expand Down

0 comments on commit b82a074

Please sign in to comment.