How to use Variables/Filters on Nested Entities in React-Apollo?

时间:2018-08-22 13:57:28

标签: apollo react-apollo apollo-client

How does one use the apollo graphql HOC's options to provide variables to nested entities?

I'm not seeing this anywhere prominent in the apollo documentation. I'm not even sure what it's called. Is "filtering on nested entities" the correct terminology?

query getPerson($id: ID!) {
    getPerson(id: $id) {
        id
        name
        utlizationData(filters: $DataFilters) {
           id
           data
        }
        productionData(filters: $DataFilters) {
           id
           data
        }

    }
 }

Usually I can just pass in an object like

let options = (props) => {
 return {
    variables: { id: props.id }
 }
};

export graphql(MY_QUERY, { options })(MyComponent);

woudl this work?

query getPerson($id: ID!, $utilizationFilter: DataFilters, $productionFilter: DataFilters) {
    getPerson(id: $id) {
        id
        name
        utilizationData(filters: $utilizationFilter) {
           id
           data
        }
        productionData(filters: $productionFilter) {
           id
           data
        }

    }
 }



let options = (props) => {
 return {
    variables: { 
        id: props.id, 
        utilizationFilter: { ...props.utilizationFilter } },
        productionFilter: { ...props.productionFilter } },
 }
};

export graphql(MY_QUERY, { options })(MyComponent);

0 个答案:

没有答案