Skip to content

Conversation

sav007
Copy link
Contributor

@sav007 sav007 commented Nov 6, 2019

Add support for encoding / decoding custom GraphQL scalar type value represented by JSON object into Map.
Add support for encoding / decoding custom GraphQL scalar type value represented by JSON list into List.

@sav007 sav007 requested a review from martinbonnin November 6, 2019 04:12
@martinbonnin
Copy link
Contributor

Just curious: are JSON objects/lists scalar types actually part of the spec or just some handy extensions that we allow ?

@sav007
Copy link
Contributor Author

sav007 commented Nov 8, 2019

@martinbonnin Well I didn't find in spec that custom scalar type should be strictly a string, and looking into the introspection query response, this is how scalar type is defined:

{
          "kind": "SCALAR",
          "name": "Date",
          "description": "The `Date` scalar type represents date format.",
          "fields": null,
          "inputFields": null,
          "interfaces": null,
          "enumValues": null,
          "possibleTypes": null
        }

At the same time custom scalar type probably should be true scalar. But in the past I remember that it was a feature request to add support to map custom scalar type into Map, like for instance to be able to map geo coordinates {"longitude": ..., "latitude": } into Map.

So yes it's probably smth we offer as convenience.

Copy link
Contributor

@martinbonnin martinbonnin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I guess users can still override the default behaviour if they're not happy with it, right ? So the default new adapters will be handy for 99% of users. Those who have specific use cases can still override them ?

@sav007
Copy link
Contributor Author

sav007 commented Nov 8, 2019

For sure, we just provide a default adapter for list and map.

@sav007 sav007 merged commit f4e43fe into apollographql:master Nov 8, 2019
@sav007 sav007 deleted the object-and-list-custom-scalar-type-support branch November 8, 2019 21:21
@taion
Copy link

taion commented Nov 13, 2019

They are explicitly allowed by the spec, which is why GraphQLJSON works. Just somewhat underdocumented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants