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

Preserve defaultValue literals #3810

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Commits on Mar 20, 2024

  1. Schema Coordinates

    Implements graphql/graphql-spec#794
    
    Adds:
    
    * DOT punctuator in lexer
    * Improvements to lexer errors around misuse of `.`
    * Minor improvement to parser core which simplified this addition
    * `SchemaCoordinate` node and `isSchemaCoodinate()` predicate
    * Support in `print()` and `visit()`
    * Added function `parseSchemaCoordinate()` since it is a parser entry point.
    * Added function `resolveSchemaCoordinate()` and `resolveASTSchemaCoordinate()` which implement the semantics (name mirrored from `buildASTSchema`) as well as the return type `ResolvedSchemaElement`
    leebyron authored and yaacovCR committed Mar 20, 2024
    Configuration menu
    Copy the full SHA
    0b41718 View commit details
    Browse the repository at this point in the history
  2. Add coordinate field to schema element definitions

    * Defines a `GraphQLSchemaElement` base class which defines a `.coordinate` property and `toString`/`toJSON` methods.
    * Adds base class to types, fields, arguments, input fields, enum values, and directives.
    * Uses this in validation error printing string templates.
    leebyron authored and yaacovCR committed Mar 20, 2024
    Configuration menu
    Copy the full SHA
    1931581 View commit details
    Browse the repository at this point in the history
  3. Add coerceInputLiteral()

    Removes `valueFromAST()` and adds `coerceInputLiteral()` as an additional export from `coerceInputValue`.
    
    The implementation is almost exactly the same as `valueFromAST()` with a slightly more strict type signature and refactored tests to improve coverage (the file unit test has 100% coverage)
    
    While this does not change any behavior, it could be breaking if you rely directly on the valueFromAST() method. Use `coerceInputLiteral()` as a direct replacement.
    leebyron authored and yaacovCR committed Mar 20, 2024
    Configuration menu
    Copy the full SHA
    e520725 View commit details
    Browse the repository at this point in the history
  4. Preserve defaultValue literals

    Fixes graphql#3051
    
    This change solves the problem of default values defined via SDL not always resolving correctly through introspection by preserving the original GraphQL literal in the schema definition. This changes argument and input field definitions `defaultValue` field from just the "value" to a new `GraphQLDefaultValueUsage` type which contains either or both "value" and "literal" fields.
    
    Since either of these fields may be set, new functions for resolving a value or literal from either have been added - `getLiteralDefaultValue` and `getCoercedDefaultValue` - these replace uses that either assumed a set value or were manually converting a value back to a literal.
    
    Here is the flow for how a default value defined in an SDL would be converted into a functional schema and back to an SDL:
    
    **Before this change:**
    
    ```
    (SDL) --parse-> (AST) --coerceInputLiteral--> (defaultValue config) --valueToAST--> (AST) --print --> (SDL)
    ```
    
    `coerceInputLiteral` performs coercion which is a one-way function, and `valueToAST` is unsafe and set to be deprecated in graphql#3049.
    
    **After this change:**
    
    ```
    (SDL) --parse-> (defaultValue literal config) --print --> (SDL)
    ```
    leebyron authored and yaacovCR committed Mar 20, 2024
    Configuration menu
    Copy the full SHA
    619c450 View commit details
    Browse the repository at this point in the history