Skip to content

Instantly share code, notes, and snippets.

Trần Văn Luận luandevpro

  • Viet Nam
Block or report user

Report or block luandevpro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Post.js
import React from 'react';
import gql from 'graphql-tag';
import { useQuery } from 'react-apollo-hooks';
import withAuth from '../lib/withAuth';
const getPosts = gql`
query getPosts($user_id: String!, $offset: Int) {
post(
offset: $offset
limit: 2
View Post.js
return Object.assign({}, prev, {
post: [...prev.post, ...fetchMoreResult.post],
});
View Post.js
<button
onClick={() =>
data.fetchMore({
variables: {
offset: data.data.post.length,
},
updateQuery: (prev, { fetchMoreResult }) => {
if (!fetchMoreResult) return prev;
return Object.assign({}, prev, {
post: [...prev.post, ...fetchMoreResult.post],
View Terminal
data: {post: Array(2)}
error: undefined
errors: undefined
fetchMore: ƒ ()
loading: false
networkStatus: 7
partial: false
refetch: ƒ ()
startPolling: ƒ ()
stopPolling: ƒ ()
View Post.js
import React from 'react';
import gql from 'graphql-tag';
import { useQuery } from 'react-apollo-hooks';
import withAuth from '../lib/withAuth';
const getPosts = gql`
query getPosts($user_id: String!, $offset: Int) {
post(
offset: $offset
limit: 2
View Post.js
import React from 'react';
import gql from 'graphql-tag';
import { useQuery } from 'react-apollo-hooks';
import withAuth from '../lib/withAuth';
const getPosts = gql`
query getPosts($user_id: String!) {
post(where: { user_id: { _eq: $user_id } }) {
id
title
View withAuth.js
import React, { useEffect, useState } from 'react';
import ApolloClient from 'apollo-client';
import { ApolloProvider } from 'react-apollo';
import { split } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { WebSocketLink } from 'apollo-link-ws';
import { getMainDefinition } from 'apollo-utilities';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider as ApolloHooksProvider } from 'react-apollo-hooks';
import { setContext } from 'apollo-link-context';
View Login.js
...
function Login() {
useEffect(
() =>
auth.onAuthStateChanged(async user => {
if (user) {
const metadataRef = await database.ref(`metadata/${user.uid}/refreshTime`);
const callback = () => {
user.getIdToken(true);
};
View Login.js
import React, { useEffect } from 'react';
import gql from 'graphql-tag';
import { auth, googleAuthProvider, database } from '../lib/firebase';
import initialApollo from '../lib/initialApollo';
const getUser = gql`
query getUser($id: String!) {
user_by_pk(id: $id) {
id
email
View initialApollo.js
import ApolloClient from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { WebSocketLink } from 'apollo-link-ws';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { split } from 'apollo-link';
import { getMainDefinition } from 'apollo-utilities';
const scheme = proto => (window.location.protocol === 'https:' ? `${proto}s` : proto);
You can’t perform that action at this time.