This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const server = new GraphQLServer({ | |
typeDefs: 'src/schema.graphql', | |
resolvers, | |
context: req => ({ | |
...req, | |
db: new Prisma({ | |
typeDefs: 'src/generated/prisma.graphql', | |
endpoint: 'YOUR_ENDPOINT_PATH', | |
secret: 'testsecret', | |
debug: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { StyleSheet, Text, View } from 'react-native'; | |
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-boost'; | |
import { ApolloProvider } from 'react-apollo'; | |
const client = new ApolloClient({ | |
link: new HttpLink(), | |
cache: new InMemoryCache() | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { StyleSheet, Text, View } from 'react-native'; | |
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-boost'; | |
import { ApolloProvider, graphql } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
const dogQuery = gql` | |
query { | |
dogs { | |
name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "RNGraphQL", | |
"version": "0.0.1", | |
"private": true, | |
"scripts": { | |
"start": "node node_modules/react-native/local-cli/cli.js start", | |
"test": "jest" | |
}, | |
"dependencies": { | |
"apollo-boost": "^0.1.22", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = new ApolloClient({ | |
link: new HttpLink({ | |
uri: 'https://eu1.prisma.sh/natalia-majkowska/dogs-service/dev', | |
headers: { | |
authorization: 'YOUR_TOKEN' // on production you need to store token | |
//in storage or in redux persist, for demonstration purposes we do this like that | |
} | |
}), | |
cache: new InMemoryCache() | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag'; | |
const dogQuery = gql` | |
query { | |
dogs { | |
name | |
type | |
} | |
} | |
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DogComponent = graphql(dogQuery)(props => { | |
const { error, dogs } = props.data; | |
if (error) { | |
return <Text>{error}</Text>; | |
} | |
if (dogs) { | |
return <Text>{dogs[0].name}</Text>; | |
} | |
return <Text>Loading...</Text>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Query { | |
dogName: String! | |
dogs: [Dog!]! | |
} | |
type Mutation { | |
dog(type: String!, name: String!): Dog! | |
updateDog(id: String!, type: String!, name: String!): Dog! | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resolvers = { | |
Query: { | |
dogName: () => `Tommy the chihuahua`, | |
dogs: (root, args, context, queryInfo) => { | |
return context.db.query.dogs({}, queryInfo); | |
} | |
}, | |
Mutation: { | |
dog: (root, args, context, queryInfo) => { | |
return context.db.mutation.createDog( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<View> | |
<Text style={styles.welcome}>Dogs data:</Text> | |
<TextInput | |
style={styles.input} | |
onChangeText={text => this.setState({ name: text })} | |
value={this.state.name} | |
placeholder="name/> | |
<TextInput |