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

Cross-resolver parameters #420

Open
mfigurski80 opened this issue Aug 11, 2020 · 1 comment
Open

Cross-resolver parameters #420

mfigurski80 opened this issue Aug 11, 2020 · 1 comment

Comments

@mfigurski80
Copy link

mfigurski80 commented Aug 11, 2020

First of all, just want to tell you that I really appreciate your work on this library so far, and my experience with is has been very positive. Of course, I'm very new and not fully familiar with it.

However, have come up against a use case recently that I'm not sure is possible to implement in Tartiflette. Specifically, looking to do more complex 'filtering' based on the properties of subfields. Am working on an experiment management platform, where we have a series of experiments and related nucleic acid (DNA) samples; was looking to be able to run a query like this:

{
  experiments(filter: {
    	type: {eq: "Experiment Type"}
    	acids: {
        	tissue: {neq: "Tissue Type"}
		}
      }
	}) {
    id
    type
    acids {
      tissue
    }
  }
}

Ideally, this structure would filter down to only experiments where the type is "Experiment Type" and which has a related acid who's tissue field is not "Tissue Type". This first level filtering is obviously straightforward, and have solved it with something like the following that would get called at every individual resolver.

def resolve_filters(df, args):
	# df is a pandas.DataFrame of the data results
    filter_fields = {
        'eq': lambda col, value: (col == value),
        'neq': lambda col, value: (col != value),
        'lt': lambda col, value: (col < value),
        'gt': lambda col, value: (col > value),
        'in': lambda col, value: ([v in value for v in col])
    }

    def resolve(col, filters):
		# check if individual col passes all filters
        pass_filter = (col == col)
        for f in filters:
            col = col.astype(type(filters[f]))
            pass_filter = pass_filter & (filter_fields[f](col, filters[f]))
        return pass_filter

    for c in args:
        if c in df:
            df = df[resolve(df[c], args[c])]
    return df

This function only resolves filters at the very top level. In my mind, the complete filtering system would have singular resolvers looking back at previously resolved data and alter those results based on it's own. Of course, this sort of ability doesn't seem to be exposed by Tartiflette. Is this something more realistic to implement as a directive?

This is something that is apparently possible in graphene, as per this issue. Has anyone encountered this use case? Any ideas about the proper way to approach this?

Again, apologies for my unfamiliarity with Tartiflette. Am hoping this is a common roadblock and that a posted issue could help myself and other people get over it.

@abusi
Copy link
Contributor

abusi commented Aug 12, 2020

i'm not sure I understand the problem.

I need more details, the filtering isn't possible inside the experiment resolver ?

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

2 participants