Skip to content

Instantly share code, notes, and snippets.

View thebestmensch's full-sized avatar
🚀
building things

James Mensch thebestmensch

🚀
building things
View GitHub Profile
const GET_DATA = ``; // some query
const WithQuery = Component => props => (
<DataQuery query={GET_DATA}>
{({ loading, error, data }) => {
if (loading) {
// ...
}
if (error) {
import Auth0Lock from 'auth0-lock';
import gql from 'graphql-tag';
import * as jwt from 'jsonwebtoken';
import { Config } from '../../../config';
const AUTH0_DOMAIN = Config.AUTH0_DOMAIN;
class AuthService {
public static isLoggedIn(): boolean {
import ApolloClient, { createNetworkInterface } from 'apollo-client';
import { AuthService } from './services'; // whatever you're using for user state
const isLoggedIn = AuthService.isLoggedIn();
const token = AuthService.getToken();
const authHeader = {
applyMiddleware(req, next) {
if (!req.options.headers) {
{
"data": {},
"errors": [
{
"message":"A foo error has occurred",
"name":"FooError",
"time_thrown":"2016-11-11T00:40:50.954Z",
"data":{
"something": "important"
}
GraphQLServer.use(
'/',
bodyParser.json(),
graphqlExpress((req) => ({ context: req.user, schema: Schema })),
);
export const userResolver = {
Query: {
async user(
_,
{ userId }, // query variable
currUser // context
) {
const psqlDriver = getPsqlDriver();
authorizeRead(userId, currUser);
@thebestmensch
thebestmensch / apollo-engine.png
Last active November 13, 2017 23:32
production-graphql-1
apollo-engine.png
[core]
engine = pg
[engine "pg"]
client = psql
[target "dev"]
uri = db:pg://postgres@localhost/postgres
[target "staging"]
-- deploy/users-email-col.sql
-- Deploy myproject:users-email-col to pg
BEGIN;
ALTER TABLE users
ADD COLUMN email VARCHAR(100);
COMMIT;
-- deploy/users.sql
-- Deploy myproject:users to pg
BEGIN;
CREATE TABLE users (
id INTEGER PRIMARY KEY,
first_name VARCHAR(45),
last_name VARCHAR(45),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),