Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffold out new transport mechanisms #3576

Closed
wants to merge 84 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
40bc81f
v3: Begin to introduce new transport.
abernix Dec 2, 2019
d90f2ec
Remove some original implementation details which are no longer relev…
abernix Dec 2, 2019
2f5e7ab
Rename tsdoc which was for a different (imported) symbol, rather than…
abernix Dec 2, 2019
c9abb68
Remove `TData` until I understand it better!
abernix Dec 2, 2019
47f52a3
Apply guard on `data` to tests which seems to make sense.
abernix Dec 2, 2019
8f4e486
Rename badly named test file.
abernix Dec 2, 2019
da84ad2
Additional progress and clarity for transports.
abernix Dec 2, 2019
3cce418
Apply suggestions from code review
abernix Dec 3, 2019
52bb1fc
Adjust incorrect TSDoc `@param` declaration which was a lie.
abernix Dec 16, 2019
9df5a54
Remove trailing space.
abernix Dec 16, 2019
e203baa
Switch `httpHandler` to use easier to read `function` call.
abernix Dec 16, 2019
04f7745
Use `isSchema` rather than `instanceof` check.
abernix Dec 16, 2019
2862d98
Address clarity-of-code comment w/r/t unclear `return` practice.
abernix Dec 16, 2019
c989b92
Add a `@throws` TSDoc annotation for possible result of `jsonBodyParse`.
abernix Dec 16, 2019
58a4675
Switch to using `@link` notation for arguments.
abernix Dec 16, 2019
353f1f1
Remove unnecessary ternary operators.
abernix Dec 16, 2019
627d8a5
Remove unused `experimental_` interfaces.
abernix Dec 16, 2019
ed6f256
Just `throw` when `req` or `res` are not set.
abernix Dec 16, 2019
eae9bb0
Re-introduce `ApolloServer.prototype.executeOperation`, for now.
abernix Dec 16, 2019
a1be448
Switch to v3 type for `VariableValues`.
abernix Dec 17, 2019
5e572d4
Remove unused (commented out) type definitions.
abernix Dec 17, 2019
1417482
Fix formatting inconsistencies between TSDoc `@remarks` instances.
abernix Dec 17, 2019
04c9f8a
Merge branch 'release-3.x' into abernix/release-3.x-transport
abernix Jan 10, 2020
c8c4fcb
Simplify tests which don't have expectations in callbacks.
abernix Jan 10, 2020
2fe7a99
Implement internal HTTP error code ability.
abernix Jan 10, 2020
c7603e8
Re-order tests to error on invalid input conditions to fail first/fast.
abernix Jan 10, 2020
9f40074
Introduce `UserContext` rather than using `Record<string,any>` everyw…
abernix Jan 10, 2020
832e6b8
Rename `processGraphqlRequest` to `processGraphqlRequestAgainstSchema`.
abernix Jan 11, 2020
c7f9a06
Rename `ProcessRequestInput` to `ProcessGraphqlRequestInput` to match…
abernix Jan 11, 2020
34b8fb1
Move TSDoc comments for `processGraphqlRequestAgainstSchema` to `inte…
abernix Jan 11, 2020
55e512d
Introduce separate types for processing functions w/ and w/o schema.
abernix Jan 11, 2020
152dbbb
Change `processHttpRequest` to accept a processor func not just `sche…
abernix Jan 11, 2020
f609f70
tsdoc: Add descriptions to the `GraphQLRequest` type.
abernix Jan 11, 2020
1c8c271
Adjust the existing `executeOperation` method to use new execution.
abernix Jan 11, 2020
38ed945
tests: Complete tests which assert receipt of req and res parameters.
abernix Jan 11, 2020
c7a1381
Protect internal methods exported for testing within a `__testing__` …
abernix Jan 13, 2020
c5ec99d
Correctly type the request listener as an `async` function.
abernix Jan 13, 2020
99a1c9e
Ensure `ServerResponse.prototype.end` is invoked in `internalServerEr…
abernix Jan 13, 2020
9008ce3
Default to status message for "500" from RFC 7231 § 6.6.1
abernix Jan 13, 2020
22666a0
Reject `jsonBodyParse` Promise on `ReadableStream`'s `error` event.
abernix Jan 13, 2020
2e7501b
Provide our own `SyntaxError` during `JSON.parse` failures on the body.
abernix Jan 13, 2020
b0d27da
Use `node-mocks-http` to mock `ServerResponse`.
abernix Jan 13, 2020
4e64b76
Use new `badRequest` in place of `internalServerError` for parse errors.
abernix Jan 13, 2020
b6e0f47
Add a note as to why something is `@ts-ignore`'d.
abernix Jan 13, 2020
06f91a8
Add some personal thoughts to a test that I'm not sure I believe in.
abernix Jan 13, 2020
06f34b2
Remove unnecessary `expect.assertions(n)` matcher.
abernix Jan 13, 2020
cd26078
Adjust formatting of error message.
abernix Jan 13, 2020
663e374
tests: Introduce tests for `jsonBodyParse`.
abernix Jan 13, 2020
4d6df45
tests: Add a test for a normal 200 status request.
abernix Jan 14, 2020
fd330b0
Merge branch 'release-3.x' into abernix/release-3.x-transport
abernix Jan 14, 2020
24e342a
Also add `node-mocks-https` to the root `package.json` + lock.
abernix Jan 15, 2020
f1c1f22
Ensure that `variables` and `extensions` are properly parsed and tested.
abernix Jan 17, 2020
cdf1b4c
Re-org: DRY up tests by using `beforeEach` calls.
abernix Jan 17, 2020
9425344
Correct imprecise explanations in TSDoc comments.
abernix Jan 20, 2020
dc0eb61
Decompose body-parsing bits in preparation for `GET` requests.
abernix Jan 20, 2020
c12b30f
tests: Change `buildRequestListenerPair` to force specification of `m…
abernix Jan 20, 2020
08624a0
Introduce support for `GET` requests.
abernix Jan 20, 2020
7ba8aa3
Remove unnecessary `req` usage, now replaced with `beforeEach`.
abernix Jan 20, 2020
4df15b2
Fix typooo in error message.
abernix Jan 22, 2020
f503a06
Avoid using `apollo-server-env` for now, opting instead for Node.js' …
abernix Jan 22, 2020
c694971
Explicitly call the `processor` a `mockProcessor`, since that's what …
abernix Jan 22, 2020
1712aab
tests: Remove testing parsing which is tested elsewhere.
abernix Jan 22, 2020
66cd30c
tests: Bring a mock test handler which behaves for both GET and POST …
abernix Jan 22, 2020
56ade2b
tests: Note what "validQuery" actually means in a comment.
abernix Jan 22, 2020
4a6e661
no-op: Comments for `mockProcessor`.
abernix Jan 22, 2020
a4a9d84
tests: Add a guard to `mockProcessor` to indicate intent.
abernix Jan 22, 2020
9d70bec
tests: Ensure that `extensions` are tested for JSON-parsing.
abernix Jan 23, 2020
858cc29
tests: Remove assertions which are scoped incorrectly.
abernix Jan 23, 2020
9d37ac7
Rename `jsonBodyParse` to `parseRequest` and adjust tests.
abernix Jan 23, 2020
28b26cd
no-op: Commentary.
abernix Jan 23, 2020
140768b
Merge branch 'release-3.x' into abernix/release-3.x-transport
abernix Jan 23, 2020
2f1ba48
Break out utility functions into `util.ts` and `util.test.ts`.
abernix Jan 23, 2020
df4ee6e
Move TODO tests away from comment which would seem to group them toge…
abernix Jan 23, 2020
ab80e3b
no-op: TSDoc spacing and typo.
abernix Jan 23, 2020
edd6c68
tests: Remove unnecessary `expect.assertions` calls.
abernix Jan 23, 2020
00e1d2a
Re-export `GraphQLError` directly from `types` module.
abernix Jan 23, 2020
caeab17
Move re-exported of `GraphQLSchemaModule` from `a-s-c` to `types` mod…
abernix Jan 23, 2020
f345380
tests: Using the correct `GraphQLSchemaModule` works (there are two!)
abernix Jan 23, 2020
b031d6c
Remove unused `Context` and `ContextFunction` types.
abernix Jan 23, 2020
185965c
Export the `httpHandler` as a top-level export.
abernix Jan 24, 2020
a00ec04
Typo-corrections from my own code review.
abernix Jan 24, 2020
7bd1949
Remove unused `export` of `GraphQLRequest` and `GraphQLResponse`.
abernix Feb 4, 2020
01be050
Feedback: Switch to using `rejects.toThrow` to assert even if resolved.
abernix Feb 4, 2020
b2ec085
tests: Feedback: Adjust types to properly indicate `Promise` of nothing.
abernix Feb 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"mock-req": "0.2.0",
"nock": "10.0.6",
"node-fetch": "2.3.0",
"node-mocks-http": "^1.8.1",
"prettier": "1.19.1",
"qs-middleware": "1.0.3",
"request": "2.88.0",
Expand Down
1 change: 1 addition & 0 deletions v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"jest": "24.9.0",
"jest-junit": "7.0.0",
"jest-matcher-utils": "24.9.0",
"node-mocks-http": "^1.8.1",
"ts-jest": "24.0.2",
"typescript": "3.7.3"
},
Expand Down
8 changes: 5 additions & 3 deletions v3/src/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApolloServer, gql } from "../index";
import { GraphQLSchemaModule } from "../types";

// TODO(AS3) Why can't I apply the `GraphQLSchemaModule` type here?
const testModule = {
const testModule: GraphQLSchemaModule = {
typeDefs: gql`
type Book {
title: String
Expand Down Expand Up @@ -33,7 +33,9 @@ describe("ApolloServer", () => {
const operation = await (new ApolloServer({
modules: [testModule],
})).executeOperation({
query: 'query GetBooks { books { author } }',
request: {
query: 'query GetBooks { books { author } }',
},
});

expect(operation).toHaveProperty(['data', 'books', 0, 'author']);
Expand Down
26 changes: 13 additions & 13 deletions v3/src/execution/__tests__/__snapshots__/execution.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ exports[`parseGraphqlRequest Returns an error for invalid queries - empty select

exports[`parseGraphqlRequest Returns an error for invalid queries - missing closing } 1`] = `[GraphQLError: Syntax Error: Expected Name, found <EOF>]`;

exports[`processGraphqlRequest Executable queries - basic - { people { name } } 1`] = `
exports[`processGraphqlRequestAgainstSchema Executable queries - basic - { people { name } } 1`] = `
Object {
"people": Array [
Object {
Expand All @@ -392,7 +392,7 @@ Object {
}
`;

exports[`processGraphqlRequest Executable queries - with directives - { people { name { friends { name } } } 1`] = `
exports[`processGraphqlRequestAgainstSchema Executable queries - with directives - { people { name { friends { name } } } 1`] = `
Object {
"people": Array [
Object {
Expand Down Expand Up @@ -455,7 +455,7 @@ Object {
}
`;

exports[`processGraphqlRequest Executable queries - with multiple documents - { people { name } } 1`] = `
exports[`processGraphqlRequestAgainstSchema Executable queries - with multiple documents - { people { name } } 1`] = `
Object {
"people": Array [
Object {
Expand All @@ -474,7 +474,7 @@ Object {
}
`;

exports[`processGraphqlRequest Executable queries - with nested selection sets - { people { name friends { name friends { name } } } } 1`] = `
exports[`processGraphqlRequestAgainstSchema Executable queries - with nested selection sets - { people { name friends { name friends { name } } } } 1`] = `
Object {
"people": Array [
Object {
Expand Down Expand Up @@ -669,38 +669,38 @@ Object {
}
`;

exports[`processGraphqlRequest Invalid queries - basic 1`] = `
exports[`processGraphqlRequestAgainstSchema Invalid queries - basic 1`] = `
Array [
[GraphQLError: Cannot query field "invalidField" on type "Query".],
]
`;

exports[`processGraphqlRequest Invalid queries - missing directive 1`] = `
exports[`processGraphqlRequestAgainstSchema Invalid queries - missing directive 1`] = `
Array [
[GraphQLError: Unknown directive "invalid".],
]
`;

exports[`processGraphqlRequest Invalid queries - with invalid selection sets 1`] = `
exports[`processGraphqlRequestAgainstSchema Invalid queries - with invalid selection sets 1`] = `
Array [
[GraphQLError: Cannot query field "invalidField" on type "Person".],
]
`;

exports[`processGraphqlRequest Invalid queries - with multiple errors 1`] = `
exports[`processGraphqlRequestAgainstSchema Invalid queries - with multiple errors 1`] = `
Array [
[GraphQLError: Cannot query field "invalidOne" on type "Person".],
[GraphQLError: Cannot query field "invalidTwo" on type "Query".],
]
`;

exports[`processGraphqlRequest Non-executable queries - error field throws 1`] = `
exports[`processGraphqlRequestAgainstSchema Non-executable queries - error field throws 1`] = `
Array [
[GraphQLError: Error while resolving \`error\` field],
]
`;

exports[`processGraphqlRequest Non-executable queries - throws multiple errors 1`] = `
exports[`processGraphqlRequestAgainstSchema Non-executable queries - throws multiple errors 1`] = `
Array [
[GraphQLError: Error while resolving \`error\` field],
[GraphQLError: Error while resolving \`nestedError\` field],
Expand All @@ -710,19 +710,19 @@ Array [
]
`;

exports[`processGraphqlRequest Unparseable queries - empty query 1`] = `
exports[`processGraphqlRequestAgainstSchema Unparseable queries - empty query 1`] = `
Array [
[GraphQLError: Syntax Error: Expected Name, found }],
]
`;

exports[`processGraphqlRequest Unparseable queries - empty selection set 1`] = `
exports[`processGraphqlRequestAgainstSchema Unparseable queries - empty selection set 1`] = `
Array [
[GraphQLError: Syntax Error: Expected Name, found }],
]
`;

exports[`processGraphqlRequest Unparseable queries - missing closing } 1`] = `
exports[`processGraphqlRequestAgainstSchema Unparseable queries - missing closing } 1`] = `
Array [
[GraphQLError: Syntax Error: Expected Name, found <EOF>],
]
Expand Down
16 changes: 8 additions & 8 deletions v3/src/execution/__tests__/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
parseGraphqlRequest,
validateGraphqlRequest,
executeGraphqlRequest,
processGraphqlRequest
processGraphqlRequestAgainstSchema
} from "..";
import { astSerializer } from "../../snapshotSerializers";
import { VariableValues, gql } from "apollo-server-core";
Expand Down Expand Up @@ -323,11 +323,11 @@ describe("executeGraphqlRequest", () => {
);
});

describe("processGraphqlRequest", () => {
describe("processGraphqlRequestAgainstSchema", () => {
it.each(validQueryTests)(
"Executable queries - %s",
async (_, { query, operationName, variables }) => {
const { data, errors } = await processGraphqlRequest({
const { data, errors } = await processGraphqlRequestAgainstSchema({
schema,
request: {
query,
Expand All @@ -344,7 +344,7 @@ describe("processGraphqlRequest", () => {
it.each(unparseableQueryTests)(
"Unparseable queries - %s",
async (_, query) => {
const { errors } = await processGraphqlRequest({
const { errors } = await processGraphqlRequestAgainstSchema({
schema,
request: {
query
Expand All @@ -358,7 +358,7 @@ describe("processGraphqlRequest", () => {
it.each(invalidQueryTests)(
"Invalid queries - %s",
async (_, { query, operationName }) => {
const { errors } = await processGraphqlRequest({
const { errors } = await processGraphqlRequestAgainstSchema({
schema,
request: {
query,
Expand All @@ -373,7 +373,7 @@ describe("processGraphqlRequest", () => {
it.each(nonExecutableQueryTests)(
"Non-executable queries - %s",
async (_, { query }) => {
const { errors } = await processGraphqlRequest({
const { errors } = await processGraphqlRequestAgainstSchema({
schema,
request: {
query
Expand All @@ -387,7 +387,7 @@ describe("processGraphqlRequest", () => {

it("Passes a modifiable context object to resolvers", async () => {
const context = Object.create(null);
const { data } = await processGraphqlRequest({
const { data } = await processGraphqlRequestAgainstSchema({
schema,
request: {
query: graphql`
Expand All @@ -399,7 +399,7 @@ describe("processGraphqlRequest", () => {
context
});

expect(data!.modifiesContext).toBe("Context modified!");
expect(data && data.modifiesContext).toBe("Context modified!");
expect(context).toHaveProperty("modified");
});
});
Loading