Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

Nested data Not working #233

Closed
gauravmakkar opened this issue Mar 27, 2018 · 3 comments
Closed

Nested data Not working #233

gauravmakkar opened this issue Mar 27, 2018 · 3 comments

Comments

@gauravmakkar
Copy link

gauravmakkar commented Mar 27, 2018

[Network error]: TypeError: Cannot read property 'ppsConfiguration' of undefined

const SELECTED_PPS_PROFILE = gql`
    query  ABCD{
        ppsConfiguration @client{
            selectedPPS @client{
                pps_id
                pps_mode
                status
                pps_profiles @client{
                    applied
                    create_time
                    pps_id
                    profile_name
                    requested
                    update_time
                }

            }
            selectedPPSProfile @client{
                applied
                profile_name
                bin_group_details @client{
                    bin_group_id
                    enabled
                    
                }
                pps_bin_details @client{
                    bin_group_id
                    bin_tags
                    breadth
                    direction
                    enabled
                    length
                    orig_cordinates
                    pps_bin_id
                }
                
            }
        }



    }
`;
const withClientData = graphql(SELECTED_PPS_PROFILE, {
    props: function(data){
        if(!data.data || !data.data.ppsConfiguration){
          return {}
        }
        return {
           selectedPPS: data.data.ppsConfiguration.selectedPPS,
           selectedPPSProfile: data.data.ppsConfiguration.selectedPPSProfile
        }
    }
})


const SELECT_PPS_PROFILE = gql`
    mutation selectPpsProfile($state: String!) {
        setSelectedProfile(state: $state) @client
    }
`;

const withSelectProfileMutations = graphql(SELECT_PPS_PROFILE, {
    props: ({mutate, ownProps}) => ({
        selectPPSProfileForConfiguration: function (state) {
            mutate({variables: {state:state}})
        },
    }),
});

-----------------------------
const ppsConfigurationState = {
    defaults: {
        ppsConfiguration:{
            __typename : "ppsConfiguration"
        }

    },
    resolvers: {
        Mutation: {
            setSelectedProfile: (_, variables, {cache}) => {
                
                let previous = {}
                previous.selectedPPS = JSON.parse(JSON.stringify(variables.state.pps))
                if (variables.state.profile) {
                    previous.selectedPPSProfile = JSON.parse(JSON.stringify(variables.state.profile))
                } else {
                    variables.state.pps.pps_profiles.forEach(function (prfl, index) {
                        if (prfl.applied) {
                            previous.selectedPPSProfile = JSON.parse(JSON.stringify(prfl))
                        }
                    })

                }



                cache.writeData({data: {ppsConfiguration: formatData(previous)}});

            }


        },
    },
};
@fbartho
Copy link
Contributor

fbartho commented Mar 27, 2018

Hi @gauravmakkar, I think I have an idea. I believe you need to have a resolver for every item tagged with @client — but ppsConfiguration does not have a resolver — conversely, I believe you don’t need @client attached to things that are sub-properties of something else that is already @client (example: bin_group_details or pps_bin_details ).

@PCreations
Copy link

Even if you implement the correct resolvers, you will struggle with this issue #226 because there is actually a problem with how we deal with nested client queries.

@hwillson
Copy link
Member

Since this is directly related to #226 (which has PR #235 associated with it), I'll close this off. Let's continue the discussions in #226. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants