-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb99371
commit 5d155f3
Showing
1 changed file
with
35 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,56 @@ | ||
import { ApolloServer } from "@apollo/server"; | ||
import { ApolloServer, ContextFunction } from "@apollo/server"; | ||
import { readFileSync } from "fs"; | ||
import gql from "graphql-tag"; | ||
import resolvers from "../resolvers"; | ||
import { buildSubgraphSchema } from "@apollo/subgraph"; | ||
import { | ||
StandaloneServerContextFunctionArgument, | ||
} from "@apollo/server/standalone"; | ||
import { DataSourceContext } from "../types/DataSourceContext"; | ||
import API from "../api"; | ||
|
||
const context: ContextFunction< | ||
[StandaloneServerContextFunctionArgument], | ||
DataSourceContext | ||
> = async ({ req }) => ({ | ||
api: new API(), | ||
}); | ||
|
||
const server = new ApolloServer({ | ||
typeDefs: gql( | ||
readFileSync("schema.graphql", { | ||
encoding: "utf-8", | ||
}) | ||
), | ||
resolvers, | ||
schema: buildSubgraphSchema({ | ||
typeDefs: gql( | ||
readFileSync("schema.graphql", { | ||
encoding: "utf-8", | ||
}) | ||
), | ||
resolvers, | ||
}), | ||
}); | ||
|
||
describe("Repository Template Functionality", () => { | ||
it("Executes Location Entity Resolver", async () => { | ||
//Arrange | ||
const query = `query ($representations: [_Any!]!) { | ||
_entities(representations: $representations) { | ||
...on Thing { | ||
name | ||
} | ||
const query = `query Capsules { | ||
capsules { | ||
id | ||
} | ||
}`; | ||
const variables = { | ||
representations: [{ __typename: "Thing", id: "1" }], | ||
}; | ||
const expected = { | ||
_entities: [{ name: "Name" }], | ||
const expected = { | ||
id: "5e9e2c5bf35918ed873b2664", | ||
}; | ||
//Act | ||
const res = await server.executeOperation({ | ||
query, | ||
variables, | ||
}); | ||
const res = await server.executeOperation( | ||
{ | ||
query, | ||
variables, | ||
}, | ||
{ contextValue: { api: new API() } } | ||
); | ||
//Assert | ||
expect(res.body.kind).toEqual("single"); | ||
expect((res.body as any).singleResult.data).toEqual(expected); | ||
expect((res.body as any).singleResult.data.capsules[0]).toEqual(expected); | ||
}); | ||
}); |