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

Resolver Ignores Subfield Values #16

Closed
fulminmaxi opened this issue Sep 23, 2020 · 2 comments · Fixed by #20
Closed

Resolver Ignores Subfield Values #16

fulminmaxi opened this issue Sep 23, 2020 · 2 comments · Fixed by #20

Comments

@fulminmaxi
Copy link

First of all, thanks for the great library!

I was using it to mock results from a search query but I encountered what looks like a bug.

To give some context, the query that I'm trying to mock takes in a string, here is what my schema looks like:

type Dog {
// ... dogfields
}

type Cat {
//... cat fields
}
union Animal = Cat | Dog

type SearchResult {
item: Animal!
rank: Int!
}

type Query {
search(str: String!): [SearchResult!]!
}

Whatever I return as item from the search resolver, Mirage just ignores it and returns the first Animal in the database.

I've put together an example repo here: https://github.com/Gamaranto/miragegraphqlbug
In the example repo, I return null as item in the search resolver, but the first animal in the db is returned anyway.

Thanks in advance for the help!

@jneurock
Copy link
Collaborator

jneurock commented Sep 23, 2020

Digging into this it looks like there are several bugs.

Quick workaround would be to add an additional resolver for the item field so it just returns what you've already included with the SearchResult:

resolvers: {
  Query: {
    search() {
      // ...what you've already got here
    }
  },
  SearchResult: {
    item: ({ item }) => item
  }
}

I will file additional issues for the related bugs:

  1. The built-in union type resolver doesn't consider the parent object argument (The built-in union type resolver doesn't consider parent records #18).
  2. Record filtering by query arguments only works when fetching records from Mirage's database at the root level. It doesn't work when filtering associated records assigned to a parent object (Associated records are not filtered by query arguments #19).

@jneurock
Copy link
Collaborator

jneurock commented Oct 2, 2020

I just merged a fix for the main issue here, which was detailed in #18.

Note: This fix won't help with https://github.com/Gamaranto/miragegraphqlbug due to the implementation of the search query resolver but some small changes will make the code work with the latest Mirage GraphQL code. I'm happy to discuss in detail but this thread is probably not the best place to chat. Feel free to hit me up on the Mirage Discord @ rocky.

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

Successfully merging a pull request may close this issue.

2 participants