-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apollo-graphql): add Apollo specific GraphQL interface. Fixes #254
- Loading branch information
Showing
8 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as chai from "chai"; | ||
import * as chaiAsPromised from "chai-as-promised"; | ||
import { ApolloGraphQLInteraction } from "./apolloGraphql"; | ||
|
||
chai.use(chaiAsPromised); | ||
const expect = chai.expect; | ||
|
||
describe("ApolloGraphQLInteraction", () => { | ||
let interaction: ApolloGraphQLInteraction; | ||
|
||
beforeEach(() => { | ||
interaction = new ApolloGraphQLInteraction(); | ||
}); | ||
|
||
describe("#withVariables", () => { | ||
describe("when given a set of variables", () => { | ||
it("should add the variables to the payload", () => { | ||
interaction.uponReceiving("a request"); | ||
interaction.withOperation("query"); | ||
interaction.withQuery("{ hello }"); | ||
interaction.withVariables({ | ||
foo: "bar" | ||
}); | ||
|
||
const json: any = interaction.json(); | ||
expect(json.request.body.variables).to.deep.eq({ foo: "bar" }); | ||
}); | ||
}); | ||
describe("when no variables are presented", () => { | ||
it("should add an empty variables property to the payload", () => { | ||
interaction.uponReceiving("a request"); | ||
interaction.withOperation("query"); | ||
interaction.withQuery("{ hello }"); | ||
|
||
const json: any = interaction.json(); | ||
expect(json.request.body).to.have.property("variables"); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("#withOperation", () => { | ||
describe("when no operationNaame is presented", () => { | ||
it("should add a null operationName property to the payload", () => { | ||
interaction.uponReceiving("a request"); | ||
interaction.withQuery("{ hello }"); | ||
|
||
const json: any = interaction.json(); | ||
expect(json.request.body).to.have.property("operationName"); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { GraphQLInteraction } from './graphql' | ||
|
||
export class ApolloGraphQLInteraction extends GraphQLInteraction { | ||
constructor() { | ||
super() | ||
this.variables = this.variables || {} | ||
this.operation = this.operation || null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters