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

examples/acephei: update for #4561 and #4453 #4583

Merged
merged 1 commit into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions examples/acephei/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cd examples/acephei
npm install
```

* *(Optional)*: Setup [Apollo Studio](https://studio.apollographql.com/) account and create your first graph. You'll need to copy the service API key for later on.
* *(Optional)*: Set up [Apollo Studio](https://studio.apollographql.com/) account and create your first graph. You'll need to copy the service API key for later on.

### Quick start script

Expand Down Expand Up @@ -57,7 +57,7 @@ The launch configurations are defined in the `.vscode/launch.json` folders withi

## Apollo Studio - Setting up your graph

If you would like to setup this example with the graph you created in your [Apollo Studio](https://studio.apollographql.com/) account, you'll need to register each downstream service using the [Apollo CLI](https://github.com/apollographql/apollo-tooling):
If you would like to set up this example with the graph you created in your [Apollo Studio](https://studio.apollographql.com/) account, you'll need to register each downstream service using the [Apollo CLI](https://github.com/apollographql/apollo-tooling):

```
apollo service:push --key={service:michael-watson:key_1234} --localSchemaFile=./services/accounts/schema.graphql --serviceName=accounts --serviceURL=http://localhost:4001
Expand Down
29 changes: 16 additions & 13 deletions examples/acephei/gateway/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { ApolloServer } from "apollo-server";
import { ApolloServerPluginUsageReporting,
ApolloServerPluginUsageReportingDisabled } from "apollo-server-core";
import { ApolloGateway, RemoteGraphQLDataSource, GatewayConfig } from "@apollo/gateway";
import DepthLimitingPlugin from "./plugins/ApolloServerPluginDepthLimiting";
import StrictOperationsPlugin from "./plugins/ApolloServerPluginStrictOperations";
import ReportForbiddenOperationsPlugin from "./plugins/ApolloServerPluginReportForbiddenOperation";

const isProd = process.env.NODE_ENV === "production";
const apolloKey = process.env.APOLLO_KEY;
const graphVariant = process.env.APOLLO_GRAPH_VARIANT || "development";
if (!process.env.APOLLO_GRAPH_VARIANT) {
process.env.APOLLO_GRAPH_VARIANT = "development";
}

class AuthenticatedDataSource extends RemoteGraphQLDataSource {
willSendRequest({ request, context }) {
Expand Down Expand Up @@ -39,7 +43,6 @@ if (!apolloKey) {
}

const apolloOperationRegistryPlugin = apolloKey ? require("apollo-server-plugin-operation-registry")({
graphVariant,
forbidUnregisteredOperations({
context, // Destructure the shared request `context`.
request: {
Expand All @@ -53,20 +56,19 @@ const apolloOperationRegistryPlugin = apolloKey ? require("apollo-server-plugin-
}
}) : {};

const apolloUsageReportingPlugin = apolloKey ? ApolloServerPluginUsageReporting({
sendVariableValues: {
all: true
},
sendHeaders: {
all: true
}
}) : ApolloServerPluginUsageReportingDisabled();

const gateway = new ApolloGateway(gatewayOptions);
const server = new ApolloServer({
gateway,
subscriptions: false, // Must be disabled with the gateway; see above.
engine: {
apiKey: apolloKey, //We set the APOLLO_KEY environment variable
graphVariant, //We set the APOLLO_GRAPH_VARIANT environment variable
sendVariableValues: {
all: true
},
sendHeaders: {
all: true
}
},
context: ({ req }) => {
// get the user token from the headers
const token = req.headers.authorization || "";
Expand All @@ -82,7 +84,8 @@ const server = new ApolloServer({
DepthLimitingPlugin({ maxDepth: 10 }),
StrictOperationsPlugin(),
ReportForbiddenOperationsPlugin({ debug: true }),
apolloOperationRegistryPlugin
apolloOperationRegistryPlugin,
apolloUsageReportingPlugin,
]
});

Expand Down
4 changes: 2 additions & 2 deletions examples/acephei/gateway/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"noUnusedLocals": false,
"forceConsistentCasingInFileNames": true,
"lib": ["es2017", "esnext.asynciterable", "dom"],
"types": ["node", "apollo-env"],
"types": ["node"],
"jsx": "react",
"baseUrl": "."
},
"include": ["./src/**/*"],
"exclude": ["**/__tests__/*", "**/__mocks__/*"]
}
}
7 changes: 5 additions & 2 deletions examples/acephei/services/accounts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApolloServer, gql, AuthenticationError } from "apollo-server";
import { ApolloServerPluginUsageReportingDisabled } from "apollo-server-core";
import { buildFederatedSchema } from "@apollo/federation";
import { readFileSync } from "fs";
import { resolve } from "path";
Expand Down Expand Up @@ -48,9 +49,11 @@ interface Context {

const server = new ApolloServer({
schema: buildFederatedSchema([{ typeDefs, resolvers }]),
engine: true,
context: ({ req }) => ({ userID: req.headers.userid }),
dataSources: () => ({ users: new UsersDataSource() })
dataSources: () => ({ users: new UsersDataSource() }),
// $APOLLO_KEY may be set in this process but that's for the gateway to report,
// not this implementing service.
plugins: [ApolloServerPluginUsageReportingDisabled()],
});

const port = process.env.PORT || 4001;
Expand Down
4 changes: 2 additions & 2 deletions examples/acephei/services/accounts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"noUnusedLocals": false,
"forceConsistentCasingInFileNames": true,
"lib": ["es2017", "esnext.asynciterable", "dom"],
"types": ["node", "apollo-env"],
"types": ["node"],
"jsx": "react",
"baseUrl": "."
},
"include": ["./src/**/*"],
"exclude": ["**/__tests__/*", "**/__mocks__/*"]
}
}
7 changes: 5 additions & 2 deletions examples/acephei/services/books/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApolloServer, gql, AuthenticationError } from "apollo-server";
import { ApolloServerPluginUsageReportingDisabled } from "apollo-server-core";
import { buildFederatedSchema } from "@apollo/federation";
import { readFileSync } from "fs";
import { resolve } from "path";
Expand Down Expand Up @@ -45,8 +46,10 @@ interface Context {

const server = new ApolloServer({
schema: buildFederatedSchema([{ typeDefs, resolvers }]),
engine: true,
dataSources: () => ({ books: new BooksDataSource() })
dataSources: () => ({ books: new BooksDataSource() }),
// $APOLLO_KEY may be set in this process but that's for the gateway to report,
// not this implementing service.
plugins: [ApolloServerPluginUsageReportingDisabled()],
});

const port = process.env.PORT || 4005;
Expand Down
4 changes: 2 additions & 2 deletions examples/acephei/services/books/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"noUnusedLocals": false,
"forceConsistentCasingInFileNames": true,
"lib": ["es2017", "esnext.asynciterable", "dom"],
"types": ["node", "apollo-env"],
"types": ["node"],
"jsx": "react",
"baseUrl": "."
},
"include": ["./src/**/*"],
"exclude": ["**/__tests__/*", "**/__mocks__/*"]
}
}
7 changes: 5 additions & 2 deletions examples/acephei/services/products/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApolloServer, gql } from "apollo-server";
import { ApolloServerPluginUsageReportingDisabled } from "apollo-server-core";
import { buildFederatedSchema } from "@apollo/federation";
import { readFileSync } from "fs";
import { resolve } from "path";
Expand Down Expand Up @@ -81,10 +82,12 @@ interface Context {

const server = new ApolloServer({
schema: buildFederatedSchema([{ typeDefs, resolvers }]),
engine: true,
dataSources: () => ({
products: new ProductsDataSource()
})
}),
// $APOLLO_KEY may be set in this process but that's for the gateway to report,
// not this implementing service.
plugins: [ApolloServerPluginUsageReportingDisabled()],
});

const port = process.env.PORT || 4003;
Expand Down
4 changes: 2 additions & 2 deletions examples/acephei/services/products/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"noUnusedLocals": false,
"forceConsistentCasingInFileNames": true,
"lib": ["es2017", "esnext.asynciterable", "dom"],
"types": ["node", "apollo-env"],
"types": ["node"],
"jsx": "react",
"baseUrl": "."
},
"include": ["./src/**/*"],
"exclude": ["**/__tests__/*", "**/__mocks__/*"]
}
}
7 changes: 5 additions & 2 deletions examples/acephei/services/reviews/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApolloServer, gql } from "apollo-server";
import { ApolloServerPluginUsageReportingDisabled } from "apollo-server-core";
import { buildFederatedSchema } from "@apollo/federation";
import { readFileSync } from "fs";
import { resolve } from "path";
Expand Down Expand Up @@ -112,11 +113,13 @@ interface Context {

const server = new ApolloServer({
schema: buildFederatedSchema([{ typeDefs, resolvers }]),
engine: true,
dataSources: () => ({
reviews: new ReviewsDataSource(),
users: new UsersDataSource()
})
}),
// $APOLLO_KEY may be set in this process but that's for the gateway to report,
// not this implementing service.
plugins: [ApolloServerPluginUsageReportingDisabled()],
});

const port = process.env.PORT || 4002;
Expand Down
4 changes: 2 additions & 2 deletions examples/acephei/services/reviews/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"noUnusedLocals": false,
"forceConsistentCasingInFileNames": true,
"lib": ["es2017", "esnext.asynciterable", "dom"],
"types": ["node", "apollo-env"],
"types": ["node"],
"jsx": "react",
"baseUrl": "."
},
"include": ["./src/**/*"],
"exclude": ["**/__tests__/*", "**/__mocks__/*"]
}
}
Loading