From 6239d274f3b92a294476de8dfac8f1a4cec78efb Mon Sep 17 00:00:00 2001 From: David Dooling Date: Fri, 13 Apr 2018 10:20:31 -0500 Subject: [PATCH] Update to new GraphQL client interface Migrate to subscription and query methods and move .graphql files under appropriate src/graphql subdirectories. --- CHANGELOG.md | 12 +++++++++- package-lock.json | 2 +- package.json | 2 +- src/commands/HelloAutomation.ts | 2 +- src/commands/HelloWorld.ts | 6 +++-- src/events/NotifyOnPush.ts | 3 +-- src/graphql/{ => query}/person.graphql | 0 src/graphql/{ => subscription}/push.graphql | 0 test/commands/HelloWorldTest.ts | 25 +++++++++++++-------- 9 files changed, 35 insertions(+), 17 deletions(-) rename src/graphql/{ => query}/person.graphql (100%) rename src/graphql/{ => subscription}/push.graphql (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e061954..a07ece9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][] -[Unreleased]: https://github.com/atomist/automation-seed-ts/compare/0.9.0...HEAD +[Unreleased]: https://github.com/atomist/automation-seed-ts/compare/0.10.0...HEAD + +## [0.10.0][] - 2018-04-13 + +[0.10.0]: https://github.com/atomist/automation-seed-ts/compare/0.9.0...0.10.0 + +GraphQL release + +### Changed + +- Updated to use new GraphQL client interfaces ## [0.9.0][] - 2018-04-10 diff --git a/package-lock.json b/package-lock.json index 606f471..93fe353 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@atomist/automation-seed", - "version": "0.9.0", + "version": "0.10.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 92b7cc7..e49bff8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@atomist/automation-seed", - "version": "0.9.0", + "version": "0.10.0", "description": "Atomist automation seed project", "author": "Atomist", "license": "Apache-2.0", diff --git a/src/commands/HelloAutomation.ts b/src/commands/HelloAutomation.ts index e15b0b4..d60ab1a 100644 --- a/src/commands/HelloAutomation.ts +++ b/src/commands/HelloAutomation.ts @@ -32,7 +32,7 @@ import { hostname } from "os"; const pj: any = require(`${appRoot.path}/package.json`); @CommandHandler("sends information about this automation back to channel", `hello ${pj.name.replace(/^@/, "")}`) -@Tags("hello") +@Tags("hello", "automation") export class HelloAutomation implements HandleCommand { public handle(ctx: HandlerContext): Promise { diff --git a/src/commands/HelloWorld.ts b/src/commands/HelloWorld.ts index 1eda3c2..2170cb2 100644 --- a/src/commands/HelloWorld.ts +++ b/src/commands/HelloWorld.ts @@ -56,8 +56,10 @@ export class HelloWorld implements HandleCommand { return Promise.resolve(Success); } - return ctx.graphClient.executeQueryFromFile("../graphql/person", - { teamId: ctx.teamId, slackUser: this.slackUser }, undefined, __dirname) + return ctx.graphClient.query({ + name: "person", + variables: { teamId: ctx.teamId, slackUser: this.slackUser }, + }) .then(result => { if (result && result.ChatTeam && result.ChatTeam[0] && result.ChatTeam[0].members && result.ChatTeam[0].members[0] && result.ChatTeam[0].members[0].person) { diff --git a/src/events/NotifyOnPush.ts b/src/events/NotifyOnPush.ts index cf18170..f39c041 100644 --- a/src/events/NotifyOnPush.ts +++ b/src/events/NotifyOnPush.ts @@ -30,8 +30,7 @@ import { import * as graphql from "../typings/types"; -@EventHandler("notify repo channels when there is a push", - GraphQL.subscriptionFromFile("../graphql/push", __dirname)) +@EventHandler("notify repo channels when there is a push", GraphQL.subscription("push")) @Tags("push", "notification") export class NotifyOnPush implements HandleEvent { diff --git a/src/graphql/person.graphql b/src/graphql/query/person.graphql similarity index 100% rename from src/graphql/person.graphql rename to src/graphql/query/person.graphql diff --git a/src/graphql/push.graphql b/src/graphql/subscription/push.graphql similarity index 100% rename from src/graphql/push.graphql rename to src/graphql/subscription/push.graphql diff --git a/test/commands/HelloWorldTest.ts b/test/commands/HelloWorldTest.ts index 1d274e4..5510bf6 100644 --- a/test/commands/HelloWorldTest.ts +++ b/test/commands/HelloWorldTest.ts @@ -34,14 +34,25 @@ describe("HelloWorld", () => { const teamId = "T79TH"; const forename = "Chancelor"; const surname = "Bennett"; + const emptyResponse = Promise.resolve({ + ChatTeam: [{ + members: [], + }], + }); it("should extract sender person", async () => { let responseMessage: string; const ctx = { graphClient: { - executeQueryFromFile(queryFile: string, params: Person.Variables): Promise { - if (params.slackUser !== hello.slackUser || params.teamId !== teamId) { - return null; + query(opts: any): Promise { + if (!opts.name || opts.name !== "person") { + return emptyResponse; + } + if (!opts.variables || opts.variables.slackUser !== hello.slackUser) { + return emptyResponse; + } + if (!opts.variables || opts.variables.teamId !== teamId) { + return emptyResponse; } return Promise.resolve({ ChatTeam: [{ @@ -74,12 +85,8 @@ describe("HelloWorld", () => { let responseMessage: string; const ctx = { graphClient: { - executeQueryFromFile(queryFile: string, params: Person.Variables): Promise { - return Promise.resolve({ - ChatTeam: [{ - members: [], - }], - }); + query(opts: any): Promise { + return emptyResponse; }, }, messageClient: {