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

Support for custom scalars #339

Open
wereHamster opened this issue Jan 15, 2019 · 0 comments
Open

Support for custom scalars #339

wereHamster opened this issue Jan 15, 2019 · 0 comments

Comments

@wereHamster
Copy link

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.

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

No branches or pull requests

1 participant