Skip to content
This repository was archived by the owner on Jul 10, 2019. It is now read-only.
This repository was archived by the owner on Jul 10, 2019. It is now read-only.

Support for custom scalars #339

@wereHamster

Description

@wereHamster

I'd like to store objects in the cache that should be treated as scalars by apollo. When writing the objects to the cache, no __typename should be required, and while reading the object no subfields should be required.

As an example, let's assume that I have such a custom TypeScript type:

type Highlight = { foo: string } | { bar: number } | { baz: boolean }

and would like to initialize the apollo client as follows:

const client = new ApolloClient({
  clientState: {
    defaults: {
      highlight: { foo: "this" }
    },
    resolvers: {
      Mutation: {
        updateHighlight: (_, { newValue }, { cache }) => {
          cache.writeData({ data: { highlight: newValue }});
          return null;
        }
      }
    }
  }
})

So that I can use it in queries, without needing to specify the fields:

query {
  highlight
}

In a schema I'd specify Highlight as a custom scalar, but I don't see any examples how to do that in apollo-link-state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions