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

Field resolution to error #36

Closed
mmjd opened this issue Jun 21, 2017 · 5 comments
Closed

Field resolution to error #36

mmjd opened this issue Jun 21, 2017 · 5 comments

Comments

@mmjd
Copy link

mmjd commented Jun 21, 2017

Hi

If in schema.js, I resolve userType to a graphqlError by throwing an exception, nothing is rendered at all and renderError of routes is not called.

I get the following error in browser:

[HMR] Waiting for update signal from WDS... asyncToGenerator.js:20 Uncaught (in promise) undefined step @ asyncToGenerator.js:20 (anonymous) @ asyncToGenerator.js:30 Promise rejected (async) settle @ asyncGenerator.js:71 resume @ asyncGenerator.js:57 (anonymous) @ asyncGenerator.js:51 Promise rejected (async) settle @ asyncGenerator.js:71 resume @ asyncGenerator.js:57 (anonymous) @ asyncGenerator.js:51 Promise rejected (async) onError @ QuerySubscription.js:66 (anonymous) @ RelayNetwork.js:76 Promise resolved (async) executeImpl @ execute.js:133 execute @ execute.js:102 Object.defineProperty.value @ graphql.js:78 graphqlImpl @ graphql.js:62 graphql @ graphql.js:50 fetchQuery @ createFetch.js:14 requestStream @ RelayNetwork.js:59 streamQuery @ RelayModernEnvironment.js:115 (anonymous) @ QuerySubscription.js:35 F @ _export.js:35 fetch @ QuerySubscription.js:30 (anonymous) @ Resolver.js:41 _callee$ @ Resolver.js:40 tryCatch @ runtime.js:65 invoke @ runtime.js:303 prototype.(anonymous function) @ runtime.js:117 resume @ asyncGenerator.js:44 (anonymous) @ asyncGenerator.js:37 F @ _export.js:35 send @ asyncGenerator.js:24 exports.default.AsyncGenerator.next @ asyncGenerator.js:105 _callee$ @ resolveRenderArgs.js:3 tryCatch @ runtime.js:65 invoke @ runtime.js:303 prototype.(anonymous function) @ runtime.js:117 resume @ asyncGenerator.js:44 (anonymous) @ asyncGenerator.js:37 F @ _export.js:35 send @ asyncGenerator.js:24 exports.default.AsyncGenerator.next @ asyncGenerator.js:105 _callee$ @ createBaseRouter.js:11 tryCatch @ runtime.js:65 invoke @ runtime.js:303 prototype.(anonymous function) @ runtime.js:117 step @ asyncToGenerator.js:17 (anonymous) @ asyncToGenerator.js:35 F @ _export.js:35 (anonymous) @ asyncToGenerator.js:14 resolveMatch @ createBaseRouter.js:11 componentDidMount @ createBaseRouter.js:58 (anonymous) @ ReactCompositeComponent.js:264 measureLifeCyclePerf @ ReactCompositeComponent.js:75 (anonymous) @ ReactCompositeComponent.js:263 notifyAll @ CallbackQueue.js:76 close @ ReactReconcileTransaction.js:80 closeAll @ Transaction.js:209 perform @ Transaction.js:156 batchedMountComponentIntoNode @ ReactMount.js:126 perform @ Transaction.js:143 batchedUpdates @ ReactDefaultBatchingStrategy.js:62 batchedUpdates @ ReactUpdates.js:97 _renderNewRootComponent @ ReactMount.js:319 _renderSubtreeIntoContainer @ ReactMount.js:401 render @ ReactMount.js:422 (anonymous) @ client.js:45 __webpack_require__ @ bootstrap 8dbbe51…:659 fn @ bootstrap 8dbbe51…:85 (anonymous) @ amd-options.js:2 __webpack_require__ @ bootstrap 8dbbe51…:659 module.exports @ bootstrap 8dbbe51…:708 (anonymous) @ bootstrap 8dbbe51…:708 client?dc71:41 [WDS] Hot Module Replacement enabled.

which is caused by QuerySubscriber --> fetch--> onError() --> reject()

graphql response is as follows:

response json: { errors: [ { message: 'this is my error message', locations: [Object], path: [Object] } ], data: { viewer: { id: 'VXNlcjptZQ==', todos: null, numTodos: 2, numCompletedTodos: 1 } } } response json: { errors: [ { message: 'this is my error message', locations: [Object], path: [Object] } ], data: { viewer: { todos: null, id: 'VXNlcjptZQ==', numTodos: 2, numCompletedTodos: 1 } } }

@taion
Copy link
Member

taion commented Jun 21, 2017

For consistency with <QueryRenderer>, data fetching errors don't yield router-level errors unless you rethrow in prerender. Just handle error rendering in the render callback as with <QueryRenderer>.

@taion taion closed this as completed Jun 21, 2017
@mmjd
Copy link
Author

mmjd commented Jun 23, 2017

I added both route-level render and top-level renderError functions but in case of graphql error response, none of the methods are called with error argument. I see the following error in console:

Uncaught (in promise) undefined

I'am stuck for handling graphql errors from server:

{ errors: [ { message: 'my custom error message' } ] }

would you please make an advise?

@taion
Copy link
Member

taion commented Jun 23, 2017

I took a closer look.

Per facebook/relay#1913, your network layer actually needs to throw if you get any errors from your back end.

Separately, https://github.com/4Catalyzer/found-relay/pull/38/files#diff-0c098dedebf1347f99e1bf83329ad9d2R65 fixes a typo that would cause rendering to fail entirely when queries have errors. That is fixed in the newest alpha: https://github.com/4Catalyzer/found-relay/releases/tag/v0.3.0-alpha.3.

@mmjd
Copy link
Author

mmjd commented Jun 24, 2017

thank you very much for your help. now, when both data and error are not null, route-level render error is populated with error but when only error exists and data is null in response, the following error is raised in console:

Uncaught (in promise) Error: Objects are not valid as a React child (found: RelayNetwork: No data returned for operationroutes_TodoApp_Query`, got error(s):
global error message

See the error source property for more information.). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of SnapshotRenderer.
at invariant (invariant.js:44)
at traverseAllChildrenImpl (traverseAllChildren.js:144)
at traverseAllChildrenImpl (traverseAllChildren.js:93)
at traverseAllChildren (traverseAllChildren.js:172)
at flattenChildren (flattenChildren.js:66)
at ReactDOMComponent._reconcilerUpdateChildren (ReactMultiChild.js:202)
at ReactDOMComponent._updateChildren (ReactMultiChild.js:310)
at ReactDOMComponent.updateChildren (ReactMultiChild.js:297)
at ReactDOMComponent._updateDOMChildren (ReactDOMComponent.js:942)
at ReactDOMComponent.updateComponent (ReactDOMComponent.js:760)
`
and renderError is not called. would you please have a look? thank you.

@taion
Copy link
Member

taion commented Jun 24, 2017

You need to actually render something in render. Regardless, renderError will not be called unless you throw an HttpError in prerender.

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