|
| 1 | +--- |
| 2 | +title: Upgrading from v16 to v17 |
| 3 | +sidebarTitle: v16 to v17 |
| 4 | +--- |
| 5 | + |
| 6 | +import { Tabs } from 'nextra/components'; |
| 7 | + |
| 8 | +# Breaking changes |
| 9 | + |
| 10 | +## Default values |
| 11 | + |
| 12 | +GraphQL schemas allow default values for input fields and arguments. Historically, GraphQL.js did not rigorously validate or coerce these |
| 13 | +defaults during schema construction, leading to potential runtime errors or inconsistencies. For example: |
| 14 | + |
| 15 | +- A default value of "5" (string) for an Int-type argument would pass schema validation but fail at runtime. |
| 16 | +- Internal serialization methods like astFromValue could produce invalid ASTs if inputs were not properly coerced. |
| 17 | + |
| 18 | +With the new changes default values will be validated and coerced during schema construction. |
| 19 | + |
| 20 | +```graphql |
| 21 | +input ExampleInput { |
| 22 | + value: Int = "invalid" # Now triggers a validation error |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +This goes hand-in-hand with the deprecation of `astFromValue` in favor of `valueToLiteral`. |
| 27 | + |
| 28 | +```ts |
| 29 | +// Before (deprecated) |
| 30 | +const defaultValue = astFromValue(internalValue, type); |
| 31 | +// After |
| 32 | +const defaultValue = valueToLiteral(externalValue, type); |
| 33 | +``` |
| 34 | + |
| 35 | +If you want to continue using the old behavior, you can use `externalDefaultValue` rather than `defaultValue` in your schema definitions. |
| 36 | + |
| 37 | +## GraphQLError constructor arguments |
| 38 | + |
| 39 | +The `GraphQLError` constructor now only accepts a message and options object as arguments. Previously, it also accepted positional arguments. |
| 40 | + |
| 41 | +```diff |
| 42 | +- new GraphQLError('message', 'source', 'positions', 'path', 'originalError', 'extensions'); |
| 43 | ++ new GraphQLError('message', { source, positions, path, originalError, extensions }); |
| 44 | +``` |
| 45 | + |
| 46 | +## `createSourceEventStream` arguments |
| 47 | + |
| 48 | +The `createSourceEventStream` function now only accepts an object as an argument. Previously, it also accepted positional arguments. |
| 49 | + |
| 50 | +```diff |
| 51 | +- createSourceEventStream(schema, document, rootValue, contextValue, variableValues, operationName); |
| 52 | ++ createSourceEventStream({ schema, document, rootValue, contextValue, variableValues, operationName }); |
| 53 | +``` |
| 54 | + |
| 55 | +## `execute` will error for incremental delivery |
| 56 | + |
| 57 | +The `execute` function will now throw an error if it sees a `@defer` or `@stream` directive. Use `experimentalExecuteIncrementally` instead. |
| 58 | +If you know you are dealing with incremental delivery requests, you can replace the import. |
| 59 | + |
| 60 | +```diff |
| 61 | +- import { execute } from 'graphql'; |
| 62 | ++ import { experimentalExecuteIncrementally as execute } from 'graphql'; |
| 63 | +``` |
| 64 | + |
| 65 | +## Remove incremental delivery support from `subscribe` |
| 66 | + |
| 67 | +In case you have fragments that you use with `defer/stream` that end up in a subscription, |
| 68 | +use the `if` argument of the directive to disable it in your subscription operation |
| 69 | + |
| 70 | +## `subscribe` return type |
| 71 | + |
| 72 | +The `subscribe` function can now also return a non-Promise value, previously this was only a Promise. |
| 73 | +This shouldn't change a lot as `await value` will still work as expected. This could lead to |
| 74 | +some typing inconsistencies though. |
| 75 | + |
| 76 | +## Remove `singleResult` from incremental results |
| 77 | + |
| 78 | +You can remove branches that check for `singleResult` in your code, as it is no longer used. |
| 79 | + |
| 80 | +## Node support |
| 81 | + |
| 82 | +Dropped support for Node 14 (subject to change) |
| 83 | + |
| 84 | +## Removed `TokenKindEnum`, `KindEnum` and `DirectiveLocationEnum` types |
| 85 | + |
| 86 | +We have removed the `TokenKindEnum`, `KindEnum` and `DirectiveLocationEnum` types, |
| 87 | +use `Kind`, `TokenKind` and `DirectiveLocation` instead. https://github.com/graphql/graphql-js/pull/3579 |
| 88 | + |
| 89 | +## Removed `graphql/subscription` module |
| 90 | + |
| 91 | +use `graphql/execution` instead for subscriptions, all execution related exports have been |
| 92 | +unified there. |
| 93 | + |
| 94 | +## Removed `GraphQLInterfaceTypeNormalizedConfig` export |
| 95 | + |
| 96 | +Use `ReturnType<GraphQLInterfaceType['toConfig']>` if you really need this |
| 97 | + |
| 98 | +## Empty AST collections will be undefined |
| 99 | + |
| 100 | +Empty AST collections will be presented by `undefined` rather than an empty array. |
| 101 | + |
| 102 | +## `Info.variableValues` |
| 103 | + |
| 104 | +The shape of `Info.variableValues` has changed to be an object containing |
| 105 | +`sources` and `coerced` as keys. |
| 106 | + |
| 107 | +A Source contains the `signature` and provided `value` pre-coercion for the |
| 108 | +variable. A `signature` is an object containing the `name`, `input-type` and |
| 109 | +`defaultValue` for the variable. |
| 110 | + |
| 111 | +## Stream directive can't be on multiple instances of the same field |
| 112 | + |
| 113 | +The `@stream` directive can't be on multiple instances of the same field, |
| 114 | +this won't pass `validate` anymore. |
| 115 | + |
| 116 | +See https://github.com/graphql/graphql-js/pull/4342 |
| 117 | + |
| 118 | +## Stream initialCount becomes non-nullable |
| 119 | + |
| 120 | +The `initialCount` argument of the `@stream` directive is now non-nullable. |
| 121 | + |
| 122 | +See https://github.com/graphql/graphql-js/pull/4322 |
| 123 | + |
| 124 | + |
| 125 | +## Removals |
| 126 | + |
| 127 | +- Removed deprecated `getOperationType` function, use `getRootType` on the `GraphQLSchema` instance instead |
| 128 | +- Removed deprecated `getVisitFn` function, use `getEnterLeaveForKind` instead |
| 129 | +- Removed deprecated `printError` and `formatError` utilities, you can use `toString` or `toJSON` on the error as a replacement |
| 130 | +- Removed deprecated `assertValidName` and `isValidNameError` utilities, use `assertName` instead |
| 131 | +- Removed deprecated `assertValidExecutionArguments` function, use `assertValidSchema` instead |
| 132 | +- Removed deprecated `getFieldDefFn` from `TypeInfo` |
| 133 | +- Removed deprecated `TypeInfo` from `validate` https://github.com/graphql/graphql-js/pull/4187 |
| 134 | + |
| 135 | +## Deprecations |
| 136 | + |
| 137 | +- Deprecated `astFromValue` use `valueToLiteral` instead, when leveraging `valueToLiteral` ensure |
| 138 | + that you are working with externally provided values i.e. the SDL provided defaultValue to a variable. |
| 139 | +- Deprecated `valueFormAST` use `coerceInputLiteral` instead |
| 140 | + |
| 141 | +## New Features |
| 142 | + |
| 143 | +- Added `hideSuggestions` option to `execute`/`validate`/`subscribe`/... to hide schema-suggestions in error messages |
| 144 | +- Added `abortSignal` option to `graphql()`, `execute()`, and `subscribe()` allows cancellation of these methods; |
| 145 | + the `abortSignal` can also be passed to field resolvers to cancel asynchronous work that they initiate. |
| 146 | +- `extensions` support `symbol` keys, in addition to the normal string keys. |
| 147 | + |
| 148 | +## New Experimental Features |
| 149 | + |
| 150 | +### Experimental Support for Incremental Delivery |
| 151 | + |
| 152 | +- [Spec PR](https://github.com/graphql/graphql-spec/pull/1110) / [RFC](https://github.com/graphql/graphql-wg/blob/main/rfcs/DeferStream.md) |
| 153 | +- enabled only when using `experimentalExecuteIncrementally()`, use of a schema or operation with `@defer`/`@stream` directives within `execute()` will now throw. |
| 154 | +- enable early execution with the new `enableEarlyExecution` configuration option for `experimentalExecuteIncrementally()`. |
| 155 | + |
| 156 | +### Experimental Support for Fragment Arguments |
| 157 | + |
| 158 | +- [Spec PR](https://github.com/graphql/graphql-spec/pull/1081) |
| 159 | +- enable with the new `experimentalFragmentArguments` configuration option for `parse()`. |
| 160 | +- new experimental `Kind.FRAGMENT_ARGUMENT` for visiting |
| 161 | +- new experimental `TypeInfo` methods and options for handling fragment arguments. |
| 162 | +- coerce AST via new function `coerceInputLiteral()` with experimental fragment variables argument (as opposed to deprecated `valueFromAST()` function). |
0 commit comments