Skip to content

Instantly share code, notes, and snippets.

View redbluenat's full-sized avatar
🏠
Working from home

Natalia MS redbluenat

🏠
Working from home
View GitHub Profile
@redbluenat
redbluenat / index-server.js
Created November 26, 2018 08:26
index-server.js
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
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()
});
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
{
"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",
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()
});
import gql from 'graphql-tag';
const dogQuery = gql`
query {
dogs {
name
type
}
}
`;
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>;
type Query {
dogName: String!
dogs: [Dog!]!
}
type Mutation {
dog(type: String!, name: String!): Dog!
updateDog(id: String!, type: String!, name: String!): Dog!
}
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(
@redbluenat
redbluenat / index.xml
Last active December 17, 2018 08:49
input layout
<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