File tree Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 3131# Application definition
3232
3333INSTALLED_APPS = [
34+ 'corsheaders' ,
3435 'django.contrib.admin' ,
3536 'django.contrib.auth' ,
3637 'django.contrib.contenttypes' ,
4950}
5051
5152MIDDLEWARE = [
53+ 'corsheaders.middleware.CorsMiddleware' ,
54+ 'django.middleware.common.CommonMiddleware' ,
5255 'django.middleware.security.SecurityMiddleware' ,
5356 'django.contrib.sessions.middleware.SessionMiddleware' ,
5457 'django.middleware.common.CommonMiddleware' ,
5962 'django.contrib.auth.middleware.AuthenticationMiddleware' ,
6063]
6164
65+ # CORS_ALLOWED_WHITELIST = (
66+ # 'localhost:3000'
67+ # )
68+ CORS_ALLOWED_ORIGINS = [
69+ 'http://localhost:3000'
70+ ]
6271AUTHENTICATION_BACKENDS = [
6372 'graphql_jwt.backends.JSONWebTokenBackend' ,
6473 'django.contrib.auth.backends.ModelBackend' ,
Original file line number Diff line number Diff line change 11import React from "react" ;
22import withRoot from "./withRoot" ;
3+ import { Query } from 'react-apollo' ;
4+ import { gql } from "apollo-boost" ;
35
4- const Root = ( ) => < div > Root</ div > ;
6+ const Root = ( ) => (
7+ < Query query = { GET_TRACKS_Q } >
8+ { ( { data, loading, error } ) => {
9+ if ( loading ) return < div > loading...</ div >
10+ if ( error ) return < div > error</ div >
11+
12+ return < div > { JSON . stringify ( data ) } </ div >
13+ } }
14+
15+ </ Query >
16+ ) ;
17+
18+ const GET_TRACKS_Q = gql `
19+ {
20+ books {
21+ id
22+ title
23+ author
24+ description
25+ }
26+ }
27+ `
528
629export default withRoot ( Root ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,20 @@ import ReactDOM from "react-dom";
33import Root from "./Root" ;
44import * as serviceWorker from "./serviceWorker" ;
55
6- ReactDOM . render ( < Root /> , document . getElementById ( "root" ) ) ;
6+ import { ApolloProvider } from 'react-apollo'
7+ import ApolloClient from 'apollo-boost'
8+
9+
10+ const client = new ApolloClient ( {
11+ uri :"http://localhost:8000/graphql/"
12+ } )
13+
14+ ReactDOM . render (
15+ < ApolloProvider client = { client } >
16+ < Root /> ,
17+ </ ApolloProvider > ,
18+ document . getElementById ( "root" )
19+ ) ;
720
821// If you want your app to work offline and load faster, you can change
922// unregister() to register() below. Note this comes with some pitfalls.
You can’t perform that action at this time.
0 commit comments