Do i need to setup gql locally first??
# prisma-whats-new
b
Do i need to setup gql locally first??
d
Do you have a repo anywhere we can take a look at?
b
doing it locally, not on github
d
Additionally, you can look at this boilerplate for a basic implementation of RN + Graphcool: https://github.com/graphql-boilerplates/react-native-fullstack-graphql/tree/master/basic
b
import { ApolloClient } from ‘apollo-client’; import { ApolloProvider } from ‘react-apollo’; import { createHttpLink } from ‘apollo-link-http’; import { setContext } from ‘apollo-link-context’; import { InMemoryCache } from ‘apollo-cache-inmemory’; import React, { Component } from ‘react’; import { Provider } from ‘react-redux’; import ‘../Config’; import RootContainer from ‘./RootContainer’; import createStore from ‘../Redux’; const httpLink = createHttpLink({ uri: ’https://api.graph.cool/simple/v1/cjcf0u5rf1oh101950h4qvgt4' }); const authLink = setContext((_, { headers }) => { // get the authentication token from local storage if it exists const token = localStorage.getItem(‘token’); // return the headers to the context so httpLink can read them return { headers: { ...headers, authorization: token ?
Bearer ${token}
: null, } }; }); const client = new ApolloClient({ link: authLink.concat(httpLink), cache: new InMemoryCache() }); // create our store const store = createStore(); /** * Provides an entry point into our application. Both index.ios.js and index.android.js * call this component first. * * We create our Redux store here, put it into a provider and then bring in our * RootContainer. * * We separate like this to play nice with React Native’s hot reloading. */ class App extends Component { render() { return ( <ApolloProvider client={client}> <Provider store={store}> <RootContainer /> </Provider> </ApolloProvider> ); } } export default App;
this is the code, sorry posted all the code
will go through the link, thx mate
was struggling whole day for this… 👍
d
Are you seeing an error?
b
yup trying to connect to local host
uri is from hosted environment
i have not created server at locally, will create the server first and then try again
d
hmm
Are you getting your RN packager mixed up with graphcool endpoint?
With that configuration, Apollo would be making a call to the endpoint provided
Can you see a network request to Graphcool for data and see it explicitly calling to localhost instead of that provided URI?
b
Running application RidersKatta ({ initialProps = { }; rootTag = 1; }) infoLog.js:17 Running application “RidersKatta” with appParams: {“rootTag”1,“initialProps”{}}. DEV === true, development-level warning are ON, performance optimizations are OFF ExceptionsManager.js:73 Unhandled (in react-apollo:Apollo(Rides)) Error: Network error: localStorage is not defined at new ApolloError (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:67162:32) at ObservableQuery.currentResult (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:67273:28) at GraphQL.dataForChild (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:71556:66) at GraphQL.render (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:71607:37) at finishClassComponent (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:10003:96) at updateClassComponent (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:9996:338) at beginWork (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:10109:28) at performUnitOfWork (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:11022:24) at workLoop (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:11041:125) at Object._invokeGuardedCallback (http://localhost:8081/index.bundle?platform=ios&amp;dev=true&amp;minify=false:8182:18) reactConsoleErrorHandler @ ExceptionsManager.js:73 console.error @ YellowBox.js:71 (anonymous) @ react-apollo.browser.umd.js:545 (anonymous) @ JSTimers.js:262 _callTimer @ JSTimers.js:154 callTimers @ JSTimers.js:411 __callFunction @ MessageQueue.js:299 (anonymous) @ MessageQueue.js:111 __guard @ MessageQueue.js:262 callFunctionReturnFlushedQueue @ MessageQueue.js:110 t @ RNDebuggerWorker.js:1
d
It's this:
const token = localStorage.getItem(‘token’);
d
Yep. the issue is in your token:
ExceptionsManager.js:73 Unhandled (in react-apollo:Apollo(Rides)) Error: Network error: localStorage is not defined
localStorage
is not an API in RN. You wanna go for
AsyncStorage
b
const token = ‘token from hosted env’
removed the localhost error
d
Try first putting in your token directly
const token = '<your token here>'
b
worked …..
yeah
👍 1
thank you very much, saved my day
i am just starting, will work with asyncstorage
✌️