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

Add path to Normalization API #200

Open
samdenty opened this issue Apr 12, 2021 · 0 comments
Open

Add path to Normalization API #200

samdenty opened this issue Apr 12, 2021 · 0 comments
Labels
cache enhancement New feature or request
Milestone

Comments

@samdenty
Copy link
Owner

samdenty commented Apr 12, 2021

Given a query for a list of objects:

query {
  something {
    items(limit: 1) {
      name
    }
  }
}

And we want to normalize an Item to the index by which it appears in items.

normalization: {
  identifier(item) {
    return item.__typename + index
  }
}

One possible way of implementing it, is a second getParent / path argument:

normalization: {
  identifier(item, { getParent, path }) {
// path ==
[
  { key: "0",         args: null,         data: { name: "" }                             },
  { key: "items",     args: { limit: 1 }, data: [{ name: "" }]                           },
  { key: "something", args: null,         data: { items: [{ name: "" }] }                },
  { key: null,        args: null,         data: { something: { items: [{ name: "" }] } } },
];


	const { key, args, parent } = getParent(item)
    
    // key == "0"
    // args == null
    // parent == [{name:""}]
    
    return item.__typename + key // aka the index
  }
}

path being an array of the keys / args / data to the root of the response

and getParent being a function which accepts any item, and returns the key/args of the item, along with the parent item (which can be fed back in)

@samdenty samdenty added this to the Demo milestone Apr 12, 2021
@samdenty samdenty changed the title Normalization API needs path Add path to Normalization API Apr 12, 2021
@samdenty samdenty added cache bug Something isn't working labels Apr 12, 2021
@samdenty samdenty changed the title Add path to Normalization API Add path to Normalization API Apr 14, 2021
@PabloSzx PabloSzx added enhancement New feature or request and removed bug Something isn't working labels Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cache enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants