Add "Any" scalar type
At a glance​
- Identifier: #325
- Stage: RFC0: Strawman
- Champion: @IvanGoncharov
- PR: Add "Any" scalar type
Timeline​
- Spec PR created on 2017-06-19 by IvanGoncharov
- Commit pushed: Add "Any" scalar type on 2017-06-19 by @IvanGoncharov
In some of our tool, we need to be able to pass an arbitrary value as an argument of a directive, i.e. value which can be anything and can’t be described as a single type. The only workaround we found is to define
scalar JSON
which can accept any JSON value including objects and arrays.Moreover, this as popular approach in the community:
- Graph.cool and Scaphold both allow user to use
JSON
scalar in their schema- graphql-type-json implements such scalar as a NPM package with 20+ packages depending on it.
- Apollo uses
scalar JSON
as an example in their documentation.AFAIK, this technique doesn’t contradict GraphQL spec and solves issues at hand. At the moment, it has very limited support from tooling since it’s not a built-in type and introspection provides you no clue beyond the name of a scalar.
The idea behind this PR is to formalize existing practice for creating
scalar JSON
but in protocol agnostic way, that’s why I propose to useAny
as the name.The last argument I have is that all type system that I know have some form of opt-out type:
any
in Flow and TypScript,void*
in C/C++,sql_variant
in SQL andObject
class​ in C#/JAVA.