Skip to content

Using a nested primary id for update and deletes #59

Open
@trevordammon

Description

@trevordammon

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.

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