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 __id field to resolve object IDs at runtime #1130

Open
nquirmbach-ebiz opened this issue Jul 12, 2023 · 1 comment
Open

Add __id field to resolve object IDs at runtime #1130

nquirmbach-ebiz opened this issue Jul 12, 2023 · 1 comment
Labels
Enhancement A new feature or improvement to Houdini's public API

Comments

@nquirmbach-ebiz
Copy link

Describe the bug

I've noticed that list operations are not working in a current project. Since I can't share the source code, I've created a sample project to reproduce the issue.

Severity

serious, but I can work around it

Steps to Reproduce the Bug

  1. Install dependencies
  2. Start application
  3. Select user
  4. Add a todo item

Expected Behaviour

The item appears in the list below.

Reproduction

https://github.com/nquirmbach-ebiz/houdini-playgrund

@AlecAivazis
Copy link
Collaborator

AlecAivazis commented Jul 18, 2023

Thanks for putting the reproduction together! I took a look and it seems like the reason the mutation isn't working is because the field that has been tagged with @list doesn't have an ID. I'm surprised to hear that ever worked but that's okay.

The best way to solve this is something that Houdini doesn't yet support so I am going to change the title a bit to reflect the feature. Let's use the query from your reproduction as an example

query UserTodos {
		users {
			data {
				id
				name
				todos {
					data @list(name: "User_Todos") {
						id
						title
						completed
					}
				}
			}
		}
	}

todos is an object with data as a field. There is no key for the object value of todos, and so the id of the parent is not being correctly computed.

The solution is to have houdini augment the schema definition for every objec type to have an __id field that the cache would resolve as a special case to encode the correct ID. You would pass to a new directive that functions similarly to @parentID but instead circumvents all of the indirect lookups:

query UserTodos {
		users {
			data {
				id
				name
				todos {
					data @list(name: "User_Todos") {
						__id
						id
						title
						completed
					}
				}
			}
		}
	}
mutation AddTodo($input: CreateTodoInput!, $listId: ID!) {
	createTodo(input: $input) {
		...User_Todos_insert @listID(value: $listId)
	}
}
export let data: PageData;

$: ({ UserTodos: store } = data);

async function add() {
  await addMutation.mutate({
	  listId: $store.data.users?.data.todos?.data.listId,
	  input: {
		  completed: false,
		  title
	  }
  });
}

If this is something you have the time and energy to implement, let me know and I can provide whatever guidance is necessary

@AlecAivazis AlecAivazis changed the title List operations seem not to work anymore Add __id field to resolve object IDs at runtime Jul 18, 2023
@AlecAivazis AlecAivazis added the Enhancement A new feature or improvement to Houdini's public API label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A new feature or improvement to Houdini's public API
Projects
None yet
Development

No branches or pull requests

2 participants