Skip to content

Instantly share code, notes, and snippets.

View akoenig's full-sized avatar
🐝

André König akoenig

🐝
View GitHub Profile
// graphql/index.js
import ApolloClient, { createNetworkInterface } from "react-apollo";
const createClient = ({ endpointUri: uri, onError }) => {
const networkInterface = createNetworkInterface({ uri });
networkInterface.useAfter([{
applyAfterware({ response }, next) {
if (response.status === 500) {
// index.js
import { render } from "react-dom";
import { ApolloProvider } from "react-apollo";
import { App } from "./App";
import { createClient } from "./graphql";
const $app = document.getElementById("app");
const client = createClient({
// index.js
import { render } from "react-dom";
import { ApolloProvider } from "react-apollo";
import { App } from "./App";
import { createClient } from "./graphql";
const $app = document.getElementById("app");
const client = createClient({
// graphql/index.js
import ApolloClient, { createNetworkInterface } from "react-apollo";
const createClient = ({ endpointUri: uri }) => {
const networkInterface = createNetworkInterface({ uri });
networkInterface.useAfter([{
applyAfterware({ response }, next) {
// Do something with the response ...
import { compose } from "recompose";
import { graphql, gql } from "react-apollo";
import { ErrorHandler } from "./components";
const NewsList = compose(
graphql(gql`
query news {
id
name
@akoenig
akoenig / index.ts
Last active March 4, 2018 07:25
Medium: M2M in GraphQL context (Invoking binding factory and perform and execute query)
import { createTelemetryBinding } from "./binding";
const app = async () => {
const telemetry = await createTelemetryBinding(
"https://kqxrmk1pr7.lp.gql.zone/graphql"
);
while (true) {
const userTelemetry = await telemetry.query.user({}, {});
@akoenig
akoenig / index.ts
Last active March 3, 2018 20:02
Medium: M2M in GraphQL context (Factory function for creating the binding)
import { readFile } from "fs";
import { join as joinPath } from "path";
import { promisify } from "util";
import fetch from "node-fetch";
import { makeRemoteExecutableSchema } from "graphql-tools";
import { createHttpLink } from "apollo-link-http";
import { Binding as TelemetryBinding } from "./telemetry";
@akoenig
akoenig / telemetry.query.graphql
Created March 3, 2018 13:53
Medium: M2M in GraphQL context (Invite Mutation)
{
user {
id
measuredAt
registrations
logins
}
}
@akoenig
akoenig / fetchUserRegistrationsInLastHour.ts
Last active March 3, 2018 13:53
Medium: M2M in GraphQL context (Fetch User Registrations In The Last Hour)
import { request } from "graphql-request";
export const fetchUserRegistrationsInLastHour = async (period: string) => {
const query = `
query UserRegistrationsWithinPeriod($period: String!) {
users(where: {
createdAt: $period
} {
id
}
@akoenig
akoenig / invite.mutation.ts
Last active March 3, 2018 12:57
Medium: M2M in GraphQL context (Invite Mutation)
interface InviteInput {
input: {
email: string;
message?: string;
}
}
const invite = async (parent, args: InviteInput, context: Context, info) => {
await context.messaging.publish({
type: "Invite",