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 / DogsScreen.js
Last active December 20, 2018 21:17
DogsScreen.js
import React, { Component } from 'react';
import { StyleSheet, Text, View, Button, Modal, TextInput } from 'react-native';
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-boost';
import { ApolloProvider, graphql, Mutation } from 'react-apollo';
import gql from 'graphql-tag';
const client = new ApolloClient({
link: new HttpLink({
uri: 'https://eu1.prisma.sh/natalia-majkowska/dogs-service/dev',
headers: {
@redbluenat
redbluenat / index.js
Created December 20, 2018 21:14
index.js
import React, { Component } from 'react';
import { StyleSheet, View, ScrollView } from 'react-native';
import { LoginScreen } from './LoginScreen';
import { DogsScreen } from './DogsScreen';
export default class App extends Component {
render() {
return (
<ScrollView style={styles.scroll}>
<View style={styles.container}>
@redbluenat
redbluenat / index.js
Created December 20, 2018 18:43
index.js
const Mutation = require('./Mutations');
const resolvers = {
Query: {
dogName: () => `Tommy the chihuahua`,
dogs: (root, args, context, queryInfo) => {
return context.db.query.dogs({}, queryInfo);
},
user: (root, args, context, info) => {
return context.db.query.user({ where: { id: root.user.id } }, info);
@redbluenat
redbluenat / Mutations.js
Created December 20, 2018 18:40
Mutations.js
const APP_SECRET = 'abcdefghijklmnopqrst';
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
signUp = async (_object, args, context, _information) => {
const password = await bcrypt.hash(args.password, 10);
const user = await context.db.mutation.createUser(
{
data: { ...args, password }
},
@redbluenat
redbluenat / datamodel.graphql
Created December 17, 2018 16:58
Data model for auth payload
type Dog {
id: ID! @unique
name: String!
type: String!
}
type User {
id: ID! @unique
name: String!
password: String!
@redbluenat
redbluenat / datamodel.graphql
Created December 17, 2018 16:34
Add type user
type Dog {
id: ID! @unique
name: String!
type: String!
}
type User {
id: ID! @unique
name: String!
password: String!
@redbluenat
redbluenat / index.js
Created December 16, 2018 21:12
render
render() {
return (
<ApolloProvider client={client}>
<View style={styles.container}>
<Mutation mutation={addDog} refetchQueries={[{ query: dogQuery }]}>
{(addDogMutation, { data }) => (
<View>
<Text style={styles.welcome}>Dogs data:</Text>
<TextInput
style={styles.input}
@redbluenat
redbluenat / index.js
Created December 16, 2018 21:10
addDog
const addDog = gql`
mutation addDog($type: String!, $name: String!) {
createDog(data: { type: $type, name: $name }) {
id
}
}
`;
@redbluenat
redbluenat / index.js
Created December 16, 2018 21:09
Import
import { ApolloProvider, graphql, Mutation } from 'react-apollo';
@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