Search code examples
apollostackapollo-serverreact-apollo

Apollo GraphQL: Child Component Re-Runs Parent Query?


I've got a parent component with an Apollo query attached:

const withData = graphql(MY_QUERY, {
    options({ userID }) {
        return {
            variables: { _id: userID}
        };
    },
    props({ data: { loading, getOneUser } }) {
        return { loading, getOneUser };
    },
});

export default compose(
    withData,
    withApollo
)(NavigatorsList);

export { getOneUser_QUERY };

I've got a child component called userPhoto embedded in the render function:

   return (
        <div>
            <userPhoto />
            [.....]
        </div>
        )

Without the child component, the withData GraphQL function runs twice, once for loading == true, and one more time with the data returned.

With the child component included, the withData GraphQL function runs three times. The third time getOneUser is undefined and my component throws an error.

How can I correct this?

Thanks in advance to all for any info.


Solution

  • Fixed. There was a syntax error in the child component that wasn't throwing an error, but was causing the query to run twice + assorted other anomalies.