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

Unions and Interfaces #316

Open
ralphchristianeclipse opened this issue Oct 22, 2018 · 1 comment
Open

Unions and Interfaces #316

ralphchristianeclipse opened this issue Oct 22, 2018 · 1 comment
Assignees
Labels
ac-local-state-na feature New addition or enhancement to existing solutions

Comments

@ralphchristianeclipse
Copy link

ralphchristianeclipse commented Oct 22, 2018

https://www.apollographql.com/docs/apollo-server/features/unions-interfaces.html

this seems to not work at all on local state.

I have this snippet which resolves the correct type depending on the user.role

const roles = {
  employers: 'Employer',
  jobseekers: 'JobSeeker'
};

  User: {
    __resolveType: user => roles[user.role],
    name: ({ name = '' }) => name,
    role: ({ role = '' }) => role
  },
  JobSeeker: {
    link: ({ id }) => ``,
    image: () => ''
  },

and do it like this on queries

query Auth {
  auth @client {
    id
    role
    ... on JobSeeker {
      link
    }
    ... on Employer {
      id
    }
  }
}

which results to a __typename of User instead of Employer or JobSeeker

i can do this manually every query but it seems reusing it on the interface level would be easier

@hwillson
Copy link
Member

__resolveType is a graphql-tools feature, and is not currently supported with local resolvers. Marking as a feature request - thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ac-local-state-na feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

2 participants