Skip to content

Commit 3e2c23c

Browse files
committed
added graphql provider test
1 parent 01242c5 commit 3e2c23c

File tree

7 files changed

+119
-27
lines changed

7 files changed

+119
-27
lines changed

pact/pact-node-provider/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const logger = require('morgan');
66
const indexRouter = require('./routes/index');
77
const usersRouter = require('./routes/users');
88
const heroesRouter = require('./routes/heroes');
9+
const graphqlRouter = require('./routes/graphql');
910
const providerStateRouter = require ('./routes/provider_state');
1011

1112
const app = express();
@@ -19,6 +20,7 @@ app.use(express.static(path.join(__dirname, 'public')));
1920
app.use('/', indexRouter);
2021
app.use('/users', usersRouter);
2122
app.use('/heroes', heroesRouter);
23+
app.use('/graphql', graphqlRouter);
2224

2325
if (process.env.PACT_MODE === 'true') {
2426
app.use('/provider-state', providerStateRouter);

pact/pact-node-provider/package-lock.json

Lines changed: 58 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pact/pact-node-provider/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
"scripts": {
66
"start": "node ./bin/www",
77
"pact:providerTests": "node ./pact/provider_tests.js",
8-
"test:pact": "start-server-and-test start http://localhost:3000 pact:providerTests"
8+
"pact:providerTests:graphql": "node ./pact/provider_tests_graphql.js",
9+
"test:pact": "start-server-and-test start http://localhost:3000 pact:providerTests",
10+
"test:pact:graphql": "start-server-and-test start http://localhost:3000 pact:providerTests:graphql"
911
},
1012
"dependencies": {
1113
"cookie-parser": "~1.4.3",
1214
"debug": "~2.6.9",
1315
"express": "~4.16.0",
16+
"express-graphql": "^0.7.1",
1417
"morgan": "~1.9.0"
1518
},
1619
"devDependencies": {
17-
"@pact-foundation/pact": "7.0.1",
20+
"@pact-foundation/pact": "7.0.3",
1821
"start-server-and-test": "^1.7.5"
1922
}
2023
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { Verifier } = require('@pact-foundation/pact');
2+
const packageJson = require('../package.json');
3+
4+
let opts = {
5+
providerBaseUrl: 'http://localhost:3000',
6+
provider: 'graphql-hero-provider',
7+
pactBrokerUrl: 'https://adesso.pact.dius.com.au',
8+
pactBrokerUsername: process.env.PACT_USERNAME,
9+
pactBrokerPassword: process.env.PACT_PASSWORD,
10+
publishVerificationResult: true,
11+
providerVersion: packageJson.version,
12+
};
13+
14+
new Verifier().verifyProvider(opts).then(function () {
15+
console.log("Pacts successfully verified!");
16+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const graphqlHTTP = require('express-graphql');
2+
const {buildSchema} = require("graphql");
3+
4+
const heroesSchema = buildSchema(`
5+
type Query {
6+
hero(id: Int!): Hero
7+
}
8+
9+
type Hero {
10+
id: Int!
11+
name: String!
12+
superpower: String!
13+
universe: String!
14+
}
15+
`);
16+
17+
const getHero = function () {
18+
return {
19+
id: 42,
20+
name: "Superman",
21+
superpower: "Flying",
22+
universe: "DC"
23+
}
24+
};
25+
26+
const root = {
27+
hero: getHero
28+
};
29+
30+
const router = graphqlHTTP({
31+
schema: heroesSchema,
32+
graphiql: true,
33+
rootValue: root
34+
});
35+
36+
module.exports = router;

pact/pact-react-consumer/src/graphql/hero.service.graphql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GraphQLHeroService {
2323
}
2424
return this.client.query({
2525
query: gql`
26-
query GetHero($heroId: Int) {
26+
query GetHero($heroId: Int!) {
2727
hero(id: $heroId) {
2828
name
2929
superpower

pact/pact-react-consumer/src/graphql/hero.service.test.graphql.pact.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('HeroService GraphQL API', () => {
2424
})
2525
.withOperation("GetHero")
2626
.withQuery(`
27-
query GetHero($heroId: Int) {
27+
query GetHero($heroId: Int!) {
2828
hero(id: $heroId) {
2929
name
3030
superpower

0 commit comments

Comments
 (0)