graphql / graphql-js

A reference implementation of GraphQL for JavaScript
http://graphql.org/graphql-js/
MIT License
20.02k stars 2.02k forks source link

Rename Coercion functions #2357

Open andimarek opened 4 years ago

andimarek commented 4 years ago

The Coercion functions for Scalars are currently named:

  1. serialize: this is result or output coercion
  2. parseValue: this is runtime object input coercion
  3. parseLiteral: this is Ast literal input coercion
  4. (See #1817): serializeAsLiteral this takes an input value and converts it to an Ast literal

I don't think the current names align very well with the spec: the spec talks about "Result Coercion" and "Input Coercion". Also parseValue doesn't parse anything, but convert a runtime input value to an internal value.

In my mental model parseValue and parseLiteral produce a internalInputValue and serializeAsLiteral converts the internalInputValue to a literal.

First rough idea (I am sure we can do better, just to start the discussion)

  1. coerceOutput or coerceResult (the spec talks about result coercion, but output would mirror input)
  2. coerceInputValue
  3. coerceInputLiteral
  4. coerceInternalValueAsLiteral

In GraphQL Java we are also thinking about renaming (and adding a 4th one) and it would be great to have a discussion about a more clear naming.

sungam3r commented 3 years ago

Just for information. GraphQL.NET in v4 has 7 methods for any scalar . See ScalarGraphType.