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

Only use query, not writeToStore。My errors ---- Missing field __typename and other field。 #5202

Closed
hytStart opened this issue Aug 19, 2019 · 6 comments

Comments

@hytStart
Copy link

When i query data from Java backend, they give me some datas which are short of some fields。

Java RD says: Java Frame missing field when this filed returns null .

image

So that Apollo client give me data: null.

Could you advise me on this issue?

// client 
export const client = new ApolloClient({
    link: from([errorLink, httpLink]),
    cache,
    defaultOptions: {
        query: {
            fetchPolicy: 'network-only',
            errorPolicy: 'all',
        },
    },
})
// query
const query = gql`
            query myQuery($subOrderSerialNos: String){
                queryOrderDetailInfoBySubOrderSerialNo(subOrderSerialNos: $subOrderSerialNos) {
                    createTime
                    bizDate
                    channelName
                    couponAmount
                    paidAmount
                    orderDetail {
                        itemTitle
                        subOrderSerialNo
                        subOrderStatusDesc
                        itemPrice
                        packageInfo {
                            firstProjectName
                            secondProjectName
                        }
                        legionInfo {
                            consultant
                        }
                        protocolInfo {
                            serviceProtocolUrl
                            rescissionProtocolUrl
                            serviceBeginDate
                            serviceEndDate
                        }
                        payInfo {
                            payDetails {
                                methodCode
                                methodName
                            }
                        }
                        insuranceInfoList {
                            policyNo
                            insuranceName
                            statusDesc
                            insurancePeriod
                            claimPeriod
                            noticeUrl
                            consignUrl
                            premium
                            learningInfo {
                                learnCount
                                scheduleCount
                                learnRate
                            }
                            claimItemList {
                                claimItemName
                                applyBeginTime
                                applyEndTime
                                reportBeginTime
                                reportEndTime
                            }
                        }
                    }
                }
            }
        `
        const params = {
            subOrderSerialNos: '20190626000043_1',
        }
        client.query({
            query,
            variables: params,
        }).then(data => {
            console.log(data)
            dispatch({
                type: 'ORDER_DETAIL_GRAPHQL_SUCCEEDED',
                payload: data,
            })
        }).catch(e => {
            console.log(e)
        })
@kinow
Copy link

kinow commented Mar 2, 2020

I think I have the same issue. We are building an API with deltas for changes in workflows states. But the Python API returns a subset of the selection.

It means our query has something like:

deltas {
  workflows {
    tasks {}
    jobs {}
  }
}

But a response may have:

deltas {
  workflows {
    tasks { ... }
    # sorry, no jobs!
  }
}

When that happens, I get a similar warning in the browser console.

image

We might get a lot of these messages, cluttering the browser console. Making it harder to find errors, and apparently causing some slowness when the console is displayed.

From what I could tell by debugging and reading parts of the code, the console.log is emitted when writing to the in-memory cache.

// XXX We'd like to throw an error, but for backwards compatibility's sake
// we just print a warning for the time being.
//throw new WriteError(`Missing field ${resultFieldKey} in ${JSON.stringify(result, null, 2).substring(0, 100)}`);
invariant.warn(
`Missing field ${resultFieldKey} in ${JSON.stringify(
result,
null,
2,
).substring(0, 100)}`,
);

It will check the selectionSet, which will contain jobs, and tasks (and __typename). But it will return undefined for jobs, and cause the invariant log. There's no flag in the invariant, so I don't believe it can be disabled in runtime?

Also tried setting the errorPolicy or pass the error or onError to watchquery/subscription functions with no success. I'll try next to find something like a NoOpCache, or a way to completely disable caching and see if the issue goes away. But would be nice if I could simply disable the warning.

@kinow
Copy link

kinow commented Mar 2, 2020

p.s.: quick hack to be able to keep developing without so many entries in the console output:

console.log = function () {}
console.warn = function () {}

@dwsutherland
Copy link

Would be nice if there's a way to ignore GraphQL violations in the result-data/response, i.e. by setting result validation to false.. (Is this possible?)

@yohan-atlan
Copy link

It's a little bit dirty but try fetchPolicy: "no-cache",

@kinow
Copy link

kinow commented Mar 19, 2020

It's a little bit dirty but try fetchPolicy: "no-cache",

Hi @yohan-atlan we've always used this option as our system shows workflows statuses, which are hard to cache.

https://github.com/kinow/cylc-ui/blob/f44be4bbe041d8373ccdfc832d750a30321402c9/src/services/workflow.service.js#L65

https://github.com/kinow/cylc-ui/blob/f44be4bbe041d8373ccdfc832d750a30321402c9/src/utils/graphql.js#L114-L123

(links from the branch I am working at the moment to add deltas to a query, and that is using the hack mentioned above to silence the warnings)

From what I recall from quickly looking at the sources in WebStorm, the message would be always logged, even without a cache. It appeared to me that it would still access the InMemoryCache, no matter what settings I had. I tried creating a client with no cache, but it failed. I guess the cache is used internally for query handling perhaps?

I just tested with 2.6.8 - I was using 2.6.4 on that branch - and the issue still happens.

@hwillson
Copy link
Member

A lot of the Apollo Client internals have changed since v3 was launched. We recommend trying a more modern version of @apollo/client. Let us know if you're still encountering this issue. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants