Skip to content

Instantly share code, notes, and snippets.

View mlg87's full-sized avatar
🇺🇦
Слава Україні

Mason Goetz mlg87

🇺🇦
Слава Україні
View GitHub Profile
@mlg87
mlg87 / localSchema.js
Created July 21, 2020 21:09
Using Apollo Client for global state management code samples - localSchema.js
// ./localSchema.js
const { loadFilesSync } = require("@graphql-tools/load-files");
const { mergeTypeDefs } = require("@graphql-tools/merge");
const loadedFiles = loadFilesSync(`${__dirname}/src/**/schema.js`);
module.exports.schema = mergeTypeDefs(loadedFiles);
@mlg87
mlg87 / codegen.yml
Last active July 21, 2020 21:10
Using Apollo Client for global state management code samples - codegen.yml
# ./codegen.yml
overwrite: true
schema:
- localSchema.js
- ${SCHEMA_PATH}/graphql: # <-- this is for our remote schema, you'll probably have something similar
headers:
Authorization: ${AUTH0_ACCESS_TOKEN}
generates:
src/types/graphql.tsx:
documents: # <-- your app structure may be different, but this will pick up the queries.ts and mutations.ts files created earlier
@mlg87
mlg87 / package.json
Created July 21, 2020 21:13
Using Apollo Client for global state management code samples - package.json
// ./package.json
{
...
"scripts": {
...
"generate:schema": "graphql-codegen -r dotenv/config"
}
}
@mlg87
mlg87 / src_AnotherThing_index.tsx
Created July 21, 2020 21:16
Using Apollo Client for global state management code samples - src/AnotherThing/index.tsx
// ./src/AnotherThing/index.tsx
import React from "react";
import { BalloonPickerThatHasAllOfTheNeededLogicInItButForSomeReasonRequiresMeToPassAMutation } from "../Balloon/Picker";
import {
useGetSelectedBalloonLocalQuery,
useGetBalloonsQuery,
useSetSelectedBalloonLocalMutation,
} from "../types/graphql";