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

Apollo Server 2: Remove formatParams #1331

Merged
merged 5 commits into from
Jul 13, 2018
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
2 changes: 1 addition & 1 deletion docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ new ApolloServer({

Add tracing or cacheControl meta data to the GraphQL response

* `formatError`, `formatResponse`, `formatParams`: <`Function`>
* `formatError`, `formatResponse`: <`Function`>

Functions to format the errors and response returned from the server, as well as the parameters to graphql execution(`runQuery`)

Expand Down
8 changes: 2 additions & 6 deletions docs/source/features/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,12 @@ Apollo Server provides two ways to log a server: per input, response, and errors

### High Level Logging

To log the inputs, response, and request, Apollo Server provides three methods: `formatParams`, `formatError`, and `formatResponse`. This example uses `console.log` to record the information, servers can use other more sophisticated tools.
To log, Apollo Server provides: `formatError` and `formatResponse`. This example uses `console.log` to record the information, servers can use other more sophisticated tools.

```js
const server = new ApolloServer({
typeDefs,
resolvers,
formatParams: params => {
console.log(params);
return params;
},
formatError: error => {
console.log(error);
return error;
Expand All @@ -67,7 +63,7 @@ server.listen().then(({ url }) => {

### Granular Logs

Additionally for more advanced cases, Apollo Server accepts an array of `graphql-extensions` to the `extensions` field. These extensions receive a variety of lifecycle calls for each phase of a GraphQL request and can keep state, such as the request headers.
For more advanced cases, Apollo Server provides an experimental api that accepts an array of `graphql-extensions` to the `extensions` field. These extensions receive a variety of lifecycle calls for each phase of a GraphQL request and can keep state, such as the request headers.

```js
const { ApolloServer } = require('apollo-server');
Expand Down
6 changes: 1 addition & 5 deletions docs/source/migration-two-dot.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,9 @@ new ApolloServer({
});
```

For most other functions that might have required access to the middleware arguments, such as `formatParams`, `formatError`, and `formatResponse`, it is possible to create a `graphql-extension`.

For more complicated use cases, the `ApolloServer` class can be extended to override the `createGraphQLServerOptions` function to create parameters based on the same argument that's passed to the context.

<h2 id="log-function">Replacing `logFunction`</h2>

Apollo Server 2 removes the `logFunction` in favor of using `graphql-extensions`, which provides a more structured and flexible way of instrumenting Apollo Server. The explanation of how to do this more granular logging, can be found in the [metrics section](./features/metrics.html)
Apollo Server 2 removes the `logFunction` to reduce the exposure of internal implementation details. The experimental, non-public `graphql-extensions` provides a more structured and flexible way of instrumenting Apollo Server. An explanation of to do more granular logging, can be found in the [metrics section](./features/metrics.html).

<h2 id="graphiql">Replacing GraphiQL</h2>

Expand Down
3 changes: 0 additions & 3 deletions docs/source/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ The above are the only options you need most of the time. Here are some others t
```js
// options object
const GraphQLOptions = {
// a function applied to the parameters of every invocation of runQuery
formatParams?: Function,

// * - (optional) validationRules: extra validation rules applied to requests
validationRules?: Array<ValidationRule>,

Expand Down
2 changes: 0 additions & 2 deletions packages/apollo-server-core/src/graphqlOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { KeyValueCache } from 'apollo-server-caching';
* - (optional) formatError: Formatting function applied to all errors before response is sent
* - (optional) rootValue: rootValue passed to GraphQL execution
* - (optional) context: the context passed to GraphQL execution
* - (optional) formatParams: a function applied to the parameters of every invocation of runQuery
* - (optional) validationRules: extra validation rules applied to requests
* - (optional) formatResponse: a function applied to each graphQL execution result
* - (optional) fieldResolver: a custom default field resolver
Expand All @@ -32,7 +31,6 @@ export interface GraphQLServerOptions<
formatError?: Function;
rootValue?: any;
context?: TContext;
formatParams?: Function;
validationRules?: Array<(context: ValidationContext) => any>;
formatResponse?: Function;
fieldResolver?: GraphQLFieldResolver<any, TContext>;
Expand Down
16 changes: 5 additions & 11 deletions packages/apollo-server-core/src/runHttpQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,11 @@ export async function runHttpQuery(
}
}

// We ensure that there is a queryString or parsedQuery after formatParams
if (queryString && typeof queryString !== 'string') {
if (!queryString) {
throw new HttpQueryError(400, 'Must provide query string.');
}

if (typeof queryString !== 'string') {
// Check for a common error first.
if (queryString && (queryString as any).kind === 'Document') {
throw new HttpQueryError(
Expand Down Expand Up @@ -406,15 +409,6 @@ export async function runHttpQuery(
persistedQueryRegister,
};

if (optionsObject.formatParams) {
params = optionsObject.formatParams(params);
}

if (!params.queryString && !params.parsedQuery) {
// Note that we've already thrown a different error if it looks like APQ.
throw new HttpQueryError(400, 'Must provide query string.');
}

return runQuery(params);
} catch (e) {
// Populate any HttpQueryError to our handler which should
Expand Down
1 change: 0 additions & 1 deletion packages/apollo-server-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export interface Config
| 'formatError'
| 'debug'
| 'rootValue'
| 'formatParams'
| 'validationRules'
| 'formatResponse'
| 'fieldResolver'
Expand Down