I'm trying to connect React with Folklore \ GraphQL from Laravel.
In ReactJS I have the following code in index.js
:
import React from 'react';
import ReactDOM from 'react-dom';
import registerServiceWorker from './registerServiceWorker';
import { ApolloClient, ApolloProvider, createNetworkInterface } from 'react-apollo';
import Devices from './components/Devices.js'
const networkInterface = createNetworkInterface({
uri: 'http://127.0.0.1:8000/graphiql',
opts: {
credentials: 'same-origin',
mode: 'no-cors',
},
});
const client = new ApolloClient({ networkInterface });
ReactDOM.render(
<ApolloProvider client={client}>
<Devices />
</ApolloProvider>,
document.getElementById('root')
)
And in Devices.js
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
class Devices extends Component {
render() {
console.log(this.props);
return(
<div>Hello</div>
);
}
}
const query = gql'
{
devices {
id_device,
name,
type,
}
}
';
export default graphql(query)(Devices);
But it shows the following error:
POST link 405 (Method Not Allowed)
And if I add the method:'GET'
in opts
shows the following error:
Unhandled (in react-apollo) Error: Network error: Failed to execute 'fetch' on 'Window': Request with GET / HEAD method can not have body.
How can you add the POST method to Folklore \ GraphQL? How can you add the GET method to ApolloClient?