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

Upgrade to AS4 [Don't Merge] #298

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions final/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"test": "react-scripts test",
"eject": "react-scripts eject",
"run:ios-demo": "npx artillery run apollo-internal-demos/ios-workload.yml",
"// TODO": "use graphql-codegen",
"codegen": "apollo client:codegen --target typescript --watch"
},
"eslintConfig": {
Expand Down
2,700 changes: 1,105 additions & 1,595 deletions final/server/package-lock.json

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions final/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
"author": "",
"license": "ISC",
"dependencies": {
"apollo-datasource": "^3.1.0",
"apollo-datasource-rest": "^3.2.0",
"apollo-server": "^3.8.1",
"@apollo/datasource-rest": "^4.3.2",
"@apollo/server": "^4.0.0",
"aws-sdk": "^2.585.0",
"dotenv": "^6.2.0",
"graphql": "^15.5.1",
"graphql": "^16.5.0",
"isemail": "^3.1.3",
"mime": "^2.4.4",
"nodemon": "^1.19.4",
Expand All @@ -25,11 +24,9 @@
"uuid": "^3.3.3"
},
"devDependencies": {
"@apollo/client": "^3.7.0",
"@apollo/rover": "^0.2.0",
"apollo-link": "^1.2.3",
"apollo-link-http": "^1.5.5",
"jest": "^25.0.0",
"nock": "^10.0.2",
"node-fetch": "^2.2.1",
"now": "^12.1.3"
},
Expand Down
115 changes: 65 additions & 50 deletions final/server/src/__tests__/__snapshots__/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,98 @@

exports[`Mutations books trips 1`] = `
Object {
"data": Object {
"bookTrips": Object {
"launches": Array [
Object {
"id": "1",
"isBooked": true,
},
Object {
"id": "2",
"isBooked": true,
"body": Object {
"kind": "single",
"singleResult": Object {
"data": Object {
"bookTrips": Object {
"launches": Array [
Object {
"id": "1",
"isBooked": true,
},
Object {
"id": "2",
"isBooked": true,
},
],
"message": "trips booked successfully",
"success": true,
},
],
"message": "trips booked successfully",
"success": true,
},
"errors": undefined,
},
},
"errors": undefined,
"extensions": undefined,
"http": Object {
"headers": Headers {
Symbol(map): Object {},
"headers": Map {
"cache-control" => "no-store",
},
"status": undefined,
},
}
`;

exports[`Queries fetches list of launches 1`] = `
Object {
"data": Object {
"launches": Object {
"cursor": "1143239400",
"hasMore": false,
"launches": Array [
Object {
"id": "1",
"isBooked": true,
"mission": Object {
"missionPatch": "https://images2.imgbox.com/40/e3/GypSkayF_o.png",
"name": "FalconSat",
},
"rocket": Object {
"name": "Falcon 1",
},
"body": Object {
"kind": "single",
"singleResult": Object {
"data": Object {
"launches": Object {
"cursor": "1143239400",
"hasMore": false,
"launches": Array [
Object {
"id": "1",
"isBooked": true,
"mission": Object {
"missionPatch": "https://images2.imgbox.com/40/e3/GypSkayF_o.png",
"name": "FalconSat",
},
"rocket": Object {
"name": "Falcon 1",
},
},
],
},
],
},
"errors": undefined,
},
},
"errors": undefined,
"extensions": undefined,
"http": Object {
"headers": Headers {
Symbol(map): Object {},
"headers": Map {
"cache-control" => "no-store",
},
"status": undefined,
},
}
`;

exports[`Queries fetches single launch 1`] = `
Object {
"data": Object {
"launch": Object {
"id": "1",
"isBooked": true,
"mission": Object {
"name": "FalconSat",
},
"rocket": Object {
"type": "Merlin A",
"body": Object {
"kind": "single",
"singleResult": Object {
"data": Object {
"launch": Object {
"id": "1",
"isBooked": true,
"mission": Object {
"name": "FalconSat",
},
"rocket": Object {
"type": "Merlin A",
},
},
},
"errors": undefined,
},
},
"errors": undefined,
"extensions": undefined,
"http": Object {
"headers": Headers {
Symbol(map): Object {},
"headers": Map {
"cache-control" => "no-store",
},
"status": undefined,
},
}
`;
70 changes: 26 additions & 44 deletions final/server/src/__tests__/__utils.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,35 @@
const { HttpLink } = require('apollo-link-http');
const fetch = require('node-fetch');
const { execute, toPromise } = require('apollo-link');

module.exports.toPromise = toPromise;

const {
dataSources,
context: defaultContext,
typeDefs,
resolvers,
ApolloServer,
LaunchAPI,
UserAPI,
store,
} = require('../');

/**
* Integration testing utils
*/
const constructTestServer = ({ context = defaultContext } = {}) => {
const userAPI = new UserAPI({ store });
const launchAPI = new LaunchAPI();

const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => ({ userAPI, launchAPI }),
context,
});

return { server, userAPI, launchAPI };
};

module.exports.constructTestServer = constructTestServer;
// @ts-check
const { HttpLink } = require("@apollo/client/link/http");
const fetch = require("node-fetch");
const { execute } = require("@apollo/client/link/core");
const { startStandaloneServer } = require("@apollo/server/standalone");
const { context } = require("../");

/**
* e2e Testing Utils
*/

const startTestServer = async server => {
// if using apollo-server-express...
const startTestServer = async (server) => {
// if using `expressMiddleware`...
// const app = express();
// server.applyMiddleware({ app });
// const httpServer = await app.listen(0);

const httpServer = await server.listen({ port: 0 });
// const httpServer = http.createServer(app);
// await server.start();
// app.use(
// cors(),
// json(),
// expressMiddleware(server, {
// context: testOptions?.context,
// }),
// );
// await new Promise((resolve) => {
// httpServer.listen({ port: 0 }, resolve);
// });
const { url } = await startStandaloneServer(server, {
context,
listen: { port: 0 },
});

const link = new HttpLink({
uri: `http://localhost:${httpServer.port}`,
uri: url,
fetch,
});

Expand All @@ -56,7 +38,7 @@ const startTestServer = async server => {

return {
link,
stop: () => httpServer.server.close(),
stop: () => server.stop(),
graphql: executeOperation,
};
};
Expand Down
9 changes: 5 additions & 4 deletions final/server/src/__tests__/e2e.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// import our production apollo-server instance
// @ts-check
// import our production @apollo/server instance
const { server } = require('../');
const gql = require('graphql-tag');

const { startTestServer, toPromise } = require('./__utils');
const { gql } = require("graphql-tag");
const { toPromise } = require("@apollo/client/link/utils");
const { startTestServer } = require('./__utils');

const LAUNCH_LIST_QUERY = gql`
query myLaunches($pageSize: Int, $after: String) {
Expand Down
Loading