How To integrate graphQL with React native and react native navigation.

I am a full stack developer. Currently doing some project on nextjs / nodejs
Working as SDE 3 in Netomi Here’s my Resume: https://resume.devaman.dev
Search for a command to run...

I am a full stack developer. Currently doing some project on nextjs / nodejs
Working as SDE 3 in Netomi Here’s my Resume: https://resume.devaman.dev
Recently i worked on Vue 3 migration. Migrating a Vue 2 application to Vue 3 is not just a dependency upgrade. The real work is in updating the application bootstrap, router, store, plugins, component

19/May/2023 While using mini-css-extract-plugin with vuejs and webpack 5, I was getting problem related to CSS priority. Scoped Css/Scss was not getting higher priority than common css. To resolve this issue we had to use oneof rule. In resourceQuery...

Hello everyone! I recently had the opportunity to work with AWS IoT to fetch real-time data. During the migration from Webpack 4 to Webpack 5, we encountered some issues with the aws-iot-device-sdk. While building our project, we encountered errors r...

Hey everyone , Webpack has released some new cool feature called module federation. Module Federation allows a JavaScript application to dynamically load code from another application and in the process, share dependencies. If an application consumi...

In this post I will tell you about on how to submit a pull request to the organization on which you are thinking to contribute. Now lets gets started with the steps... 1) Step 1 : Fork the repo. 2) Step 2 : Clone the repository.Open the terminal and ...

Amit Chambial Blog.
14 posts
Full Stack Developer and a maker. See my portfolio at https://portfolio.devaman.dev
For me , it was one of the most time consuming task as a beginner. There was no proper article related to integrating react-native, react-navigation and Apollo Client.
Create a react-native project .
react-native init ProjectName
Install Package react-navigation and apollo-client
Don't use apollo-boost package , it will give error.
npm i -S react-navigation apollo-client apollo-cache-inmemory apollo-link-http graphql graphql-tag react-apollo
import { createStackNavigator, createDrawerNavigator, createAppContainer } from ‘react-navigation’;
import HomeScreen from ‘./screens/HomeScreen’
import GoalScreen from ‘./screens/Goals/Goals’;
const MainNavigator = createDrawerNavigator({
Home: {
screen: HomeScreen ,// HomeScreen Component
path: 'auth/:token'
},
Goals: {
screen: GoalScreen,// GoalScreen Component
path: 'goals/:id'
}
}, {
initialRouteName: “Goals”,
})
const App = createAppContainer(MainNavigator)
HomeScreen.js
import { ApolloProvider } from 'react-apollo'
import ApolloClient from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import MainNavigator from './MainNavigator'
const withProvider = (Component,navigationOptions)=>{
const cache = new InMemoryCache();
const link = new HttpLink({
uri: 'http://myurl.com',
})
const client = new ApolloClient({
link,
cache,
defaultOptions
});
return class extends React.Component {
static navigationOptions = navigationOptions;
render(){
return(
<ApolloProvider client={client}>
<Component props={this.props} client={client}/>
</ApolloProvider>
)
}
}
}
const GoalScreen = createStackNavigator({
Goals: {
screen: MainNavigator,// Component nested inside Goals
}
})
export default Goals = withProvider(createAppContainer((GoalScreen)),
{
header:"Goals"
}
);
I have passed client to the component. Now we can use this client props to fire query and mutations. For eg:
this.props.client.query({
query:MY_QUERY,
variables:{name:value}
})
this.props.client.mutate({
mutation:MY_MUTATION,
variables:{name:value}
})
This made my day. Using <Query/> for running graphQL queries was cumbersome.
My example react native app: PHGoals - Apps on Google Play I have made this app during maker festival 2.0. Do upvote on product hunt.