Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a nested primary id for update and deletes #59

Open
trevordammon opened this issue Jul 15, 2021 · 0 comments
Open

Using a nested primary id for update and deletes #59

trevordammon opened this issue Jul 15, 2021 · 0 comments

Comments

@trevordammon
Copy link

I am trying to make a graphql update to a data object on my mock server. The data object's primary key is nested in another object. The structure looks like this:
type PersonId {

  id_: String!
}

type Person {
  person_id: PersonId
  name: Name!
}

In my Apollo Client I declare that keyField as primary:

const options = {
  typePolicies: {
    Person: {
      keyFields: ['person_id', ['id_']],
    },
  },
};

export const client = new ApolloClient({
  uri: '/graphql',
  cache: new InMemoryCache(options),
});

However I am not able perform updates using that nested id.

I expect to be able to make updates to the People object with:

const people = server.schema.db._collections.filter(
                (record) => record.name === 'people',
              );

const updatedPerson = people[0].update({primary_id:{id_:args.id_}} {
                name: {
                  first_name: args.first_name,
                  last_name: args.last_name,
                  middle_name: args.middle_name,
                },
                person_id: { id_: args.id_ },
              });

I have been working on this for quite a while and I can make the update when the id is on the People object but I can't seem to get things functioning with the nested structure.

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

No branches or pull requests

1 participant