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

Server request fails with undefined reasons #375

Closed
aweary opened this issue Sep 23, 2015 · 4 comments
Closed

Server request fails with undefined reasons #375

aweary opened this issue Sep 23, 2015 · 4 comments

Comments

@aweary
Copy link
Contributor

aweary commented Sep 23, 2015

I have a really simple Relay app at the moment which fails with the error:

Server request for query `RootQueryType` failed for the following reasons:

1. undefined

_markAsRejected                 @  relay.js:7313
_handleSubtractedQueryFailure   @  relay.js:7294
tryCallOne                      @  relay.js:3340
(anonymous function)            @  relay.js:3406
flush                           @  relay.js:8759

The query that is supposed to be submitted to my API is, according to the _printedQuery property:

"query RootQueryType{property{...__RelayQueryFragment0nrk9vk}} fragment __RelayQueryFragment0nrk9vk on Property{propertyName,id}"

Which I've verified returns the expected results if I run the query directly against the server using curl. My API is running on a different port so I'm using Relay.injectNetworkLayer to point Relay to the proper endpoint. I've noticed that, whenever I start my Relay application, my GraphQL API logs the request.body as an empty object, which says to me that its making the request but not with the right information.

Here are my files, as they pertain to the Relay app:

app.js

import Property from './components/Property';
import AppHomeRoute from './routes/AppHomeRoute';

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer('http://localhost:3000/')
);

ReactDOM.render(
  <Relay.RootContainer
    Component={Property}
    route={new AppHomeRoute()}
  />,
  document.getElementById('root')
);

components/Property.js

import 'babel/polyfill';
import '../../styles/main.css';

class Property extends React.Component {
    render() {
      return (
        <div>
          <h1> Working! </h1>
        </div>
      );
    }
}

export default Relay.createContainer(Property, {
  fragments: {
    property: () => Relay.QL`
      fragment on Property {
        propertyName,
        id
      }
    `
  }
});

routes/AppHomeRoute.js

export default class extends Relay.Route {
  static queries = {
    property: () => Relay.QL`
       query RootQueryType {
         property
      }
    `
  };
  static routeName = 'PropertyRoute';
}

I'm hoping its just user error, but in any case it shouldn't be returning undefined as a reason.

@aweary aweary closed this as completed Sep 23, 2015
@aweary aweary reopened this Sep 23, 2015
@aweary
Copy link
Contributor Author

aweary commented Sep 23, 2015

Looks like the issue was that Relay was setting the Content-Type header to application/json and my API was set to parse application/graphql.

Should application/graphql be supported?

@fson
Copy link
Contributor

fson commented Sep 23, 2015

@aweary express-graphql supports both.

  • application/json means the body is JSON, e.g.
{"query": "{viewer{id}}", "variables": {}}
  • application/graphql means the body is the query string itself, e.g.
{viewer{id}}

The default network layer in Relay always uses application/json.

@josephsavona
Copy link
Contributor

@fson beat me to it - Relay sends JSON, hence application/json.

@aweary
Copy link
Contributor Author

aweary commented Sep 23, 2015

👍

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

3 participants