Skip to content

Instantly share code, notes, and snippets.

View phpsmarter's full-sized avatar

ReactSmarter phpsmarter

View GitHub Profile
function delay(milliseconds: number, count: number): Promise<number> {
return new Promise<number>(resolve => {
setTimeout(() => {
resolve(count);
}, milliseconds);
});
}
// async function always returns a Promise
async function dramaticWelcome(): Promise<void> {
function (root, args, context, info) {
return __awaiter(_this, void 0, void 0, function () {
var fragments, document, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
fragments = Object.keys(info.fragments).map(function (fragment) { return info.fragments[fragment]; });
document = {
kind: graphql_1.Kind.DOCUMENT,
definitions: [info.operation].concat(fragments),
@phpsmarter
phpsmarter / airbnb_datamodel.js
Last active February 25, 2018 00:58
Prisma|airbnb_datamodel
type User {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
firstName: String!
lastName: String!
email: String! @unique
password: String!
phone: String!
responseRate: Float
@phpsmarter
phpsmarter / RNAP-init.js
Created February 23, 2018 12:59
非常好的配置方法
import { ApolloClient, createNetworkInterface } from 'react-apollo';
import { SubscriptionClient } from 'subscriptions-transport-ws';
import { addGraphQLSubscriptions } from 'add-graphql-subscriptions';
import { AsyncStorage } from 'react-native';
import { SERVER_ENDPOINT, SERVER_SUBSCRIPTION_ENDPOINT } from 'env';
let apolloClient = null;
const create = async (initialState = {}) => {
const token = await AsyncStorage.getItem('token');
@phpsmarter
phpsmarter / app.js
Last active February 23, 2018 11:30
Apollo-Mongodb-Server
const express = require('express');
const bodyParser = require('body-parser');
const Mongoose = require('mongoose');
const PORT = 8080;
const app = express();
const { apolloExpress, graphiqlExpress } = require('apollo-server');
const { makeExecutableSchema } = require('graphql-tools');
Mongoose.Promise = global.Promise;
@phpsmarter
phpsmarter / AsyncStorage-async-awati.js
Last active February 23, 2018 09:21
AsyncStorage async/await
import { AsyncStorage } from 'react-native';
// retrieve
export const retrieve = async (key) => await AsyncStorage.getItem(key);
// store
export const store = async (key, value) => {
await AsyncStorage.setItem(key, value);
}
@phpsmarter
phpsmarter / Faq-item.json
Last active February 22, 2018 07:08
f8app-datamodel
{
"_id" : "Rc3e0u89Ao",
"answer" : "If you require special assistance, auxiliary aids, or other reasonable accommodations to fully participate in this event, please email [email protected]. Information regarding disabilities and special assistance will remain confidential.",
"question" : "Are there accommodations for people with disabilities and those requiring special assistance?",
"_updated_at" : ISODate("2016-10-07T18:46:01.032+0000"),
"_created_at" : ISODate("2016-10-07T18:46:01.032+0000")
}
@phpsmarter
phpsmarter / graphql-yoga-todo.js
Created February 21, 2018 13:39
graphql-yoga-simple-todo
const { GraphQLServer } = require('graphql-yoga');
let count = 2;
let todos = [{
id: '0',
content: 'Buy milk',
isCompleted: true
},
{
id: '1',
@phpsmarter
phpsmarter / querycomponent.js
Created February 20, 2018 02:10
query components
import gql from 'graphql-tag';
import { Query } from 'react-apollo';
const query = gql`
query SomeQuery {
foo {
bar
baz
}
}
@phpsmarter
phpsmarter / login.apollo.js
Created February 20, 2018 00:26
apollo-client mutation
signup = async () => {
const { email, password } = this.state;
try {
const result = await this.props.signupUserMutation({
variables: {
email,
password,
},
});