Skip to content

Instantly share code, notes, and snippets.

@steveluscher
Last active September 26, 2016 13:01
Show Gist options
  • Save steveluscher/ffc1dfefbb10ad280c8a4c520a5c201c to your computer and use it in GitHub Desktop.
Save steveluscher/ffc1dfefbb10ad280c8a4c520a5c201c to your computer and use it in GitHub Desktop.

Revisions

  1. steveluscher revised this gist May 23, 2016. 1 changed file with 45 additions and 37 deletions.
    82 changes: 45 additions & 37 deletions graphql-js-migration-guide.md
    Original file line number Diff line number Diff line change
    @@ -4,51 +4,59 @@ This version of `graphql-js` introduces a breaking change to the method signatur

    Previously, `resolve()` had this method signature:

    type GraphQLResolveInfo = {
    fieldName: string,
    fieldASTs: Array<Field>,
    returnType: GraphQLOutputType,
    parentType: GraphQLCompositeType,
    schema: GraphQLSchema,
    fragments: { [fragmentName: string]: FragmentDefinition },
    rootValue: mixed,
    operation: OperationDefinition,
    variableValues: { [variableName: string]: mixed },
    };

    resolve(
    source: mixed,
    args: {[argName: string]: mixed},
    info: GraphQLResolveInfo
    ): mixed
    ```js
    type GraphQLResolveInfo = {
    fieldName: string,
    fieldASTs: Array<Field>,
    returnType: GraphQLOutputType,
    parentType: GraphQLCompositeType,
    schema: GraphQLSchema,
    fragments: { [fragmentName: string]: FragmentDefinition },
    rootValue: mixed,
    operation: OperationDefinition,
    variableValues: { [variableName: string]: mixed },
    };

    resolve(
    source: mixed,
    args: {[argName: string]: mixed},
    info: GraphQLResolveInfo
    ): mixed
    ```

    Typically, when you wanted to thread request or other context-specific information down to the resolve functions, you might have included it in `rootValue` when calling `graphql()`:

    // Pre 0.6.0
    graphql(req => {
    return {
    rootValue: {viewer: req.userID},
    schema,
    };
    });
    ```js
    // Pre 0.6.0
    graphql(req => {
    return {
    rootValue: {viewer: req.userID},
    schema,
    };
    });
    ```

    Now there exists a bonafide `context` property that you can set for exactly this purpose:

    // New in 0.6.0
    graphql(req => {
    return {
    context: {viewer: req.userID}, // NEW
    schema,
    };
    });
    ```js
    // New in 0.6.0
    graphql(req => {
    return {
    context: {viewer: req.userID}, // NEW
    schema,
    };
    });
    ```

    `graphql-js` 0.6.0 will make this `context` prop available to each one of your `resolve()` methods as the third argument:

    resolve(
    source: mixed,
    args: {[argName: string]: mixed},
    context: mixed, // NEW
    info: GraphQLResolveInfo // MOVED
    ): mixed
    ```js
    resolve(
    source: mixed,
    args: {[argName: string]: mixed},
    context: mixed, // NEW
    info: GraphQLResolveInfo // MOVED
    ): mixed
    ```

    Note that the `info` argument has moved to the fourth position. Anyone previously making use of the `info` argument will have to update the method signatures of their `resolve()` methods.
  2. steveluscher created this gist May 23, 2016.
    54 changes: 54 additions & 0 deletions graphql-js-migration-guide.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    # GraphQL 0.6.0 migration guide

    This version of `graphql-js` introduces a breaking change to the method signature of the `resolve()` method.

    Previously, `resolve()` had this method signature:

    type GraphQLResolveInfo = {
    fieldName: string,
    fieldASTs: Array<Field>,
    returnType: GraphQLOutputType,
    parentType: GraphQLCompositeType,
    schema: GraphQLSchema,
    fragments: { [fragmentName: string]: FragmentDefinition },
    rootValue: mixed,
    operation: OperationDefinition,
    variableValues: { [variableName: string]: mixed },
    };

    resolve(
    source: mixed,
    args: {[argName: string]: mixed},
    info: GraphQLResolveInfo
    ): mixed

    Typically, when you wanted to thread request or other context-specific information down to the resolve functions, you might have included it in `rootValue` when calling `graphql()`:

    // Pre 0.6.0
    graphql(req => {
    return {
    rootValue: {viewer: req.userID},
    schema,
    };
    });

    Now there exists a bonafide `context` property that you can set for exactly this purpose:

    // New in 0.6.0
    graphql(req => {
    return {
    context: {viewer: req.userID}, // NEW
    schema,
    };
    });

    `graphql-js` 0.6.0 will make this `context` prop available to each one of your `resolve()` methods as the third argument:

    resolve(
    source: mixed,
    args: {[argName: string]: mixed},
    context: mixed, // NEW
    info: GraphQLResolveInfo // MOVED
    ): mixed

    Note that the `info` argument has moved to the fourth position. Anyone previously making use of the `info` argument will have to update the method signatures of their `resolve()` methods.