Skip to content

Instantly share code, notes, and snippets.

View danielrearden's full-sized avatar

Daniel Rearden danielrearden

View GitHub Profile
@danielrearden
danielrearden / example.graphql
Created June 24, 2024 03:57
Example GraphQL query
query {
viewer {
gists (first: 100, orderBy: {field: CREATED_AT, direction: DESC} ) {
edges {
node {
createdAt
description
name
pushedAt
stargazers (first: 100) {
@danielrearden
danielrearden / createJunctionConnectionLoaderClass.ts
Created October 26, 2020 15:25
createJunctionConnectionLoaderClass
import DataLoader from 'dataloader';
import _ from 'lodash';
import {
sql,
DatabaseConnectionType,
IdentifierSqlTokenType,
PrimitiveValueExpressionType,
SqlSqlTokenType,
SqlTokenType,
@danielrearden
danielrearden / createConnectionLoaderClass.ts
Created October 26, 2020 15:12
createConnectionLoaderClass
/* eslint-disable @typescript-eslint/ban-types, @typescript-eslint/explicit-module-boundary-types, fp/no-this, max-nested-callbacks */
import DataLoader from 'dataloader';
import _ from 'lodash';
import {
sql,
DatabaseConnectionType,
IdentifierSqlTokenType,
PrimitiveValueExpressionType,
SqlSqlTokenType,
@danielrearden
danielrearden / test.ts
Last active December 30, 2020 12:41
test.ts
/**
* Here we have type definitions and resolvers for a GraphQL schema. Also shown is the type for the context object passed
* to each resolver (other types have been omitted for brevity). Each resolver has one issue with it that will cause
* GraphQL to return an error if that field is requested. In a few sentences, explain what is wrong with each resolver
* and what you would change to fix it.
*/
interface Context {
db: DB;
rest: Rest;
@danielrearden
danielrearden / schema-patterns.md
Last active June 30, 2020 04:24
Schema Patterns by Provider

This document summarizes the schema patterns employed by popular GraphQL APIs, frameworks and service providers. The shown types maybe be incomplete and not completely correct with regard to nullability or type names; however, they should provide a general idea of the capabilities of each provider.

Where appropriate, the shown types illustrate basic features like filtering, sorting and pagination. Providers may expose additional capabilities that are not illustrated in this document.

Find One

AWS Amplify
@danielrearden
danielrearden / 1-sqlmancer.config.js
Last active June 26, 2020 23:46
Sqlmancer Models
module.exports = {
db: Knex(...),
models: 'src/graphql',
generate: {
client: {
// ready-to-use SqlmancerClient instance, no additional initialization needed
output: 'src/sqlmancer.js'
},
typeDefs: {
output: 'src/graphql/base.graphql'
@danielrearden
danielrearden / index.ts
Created May 15, 2020 04:14
Making GraphQL Magic with Sqlmancer - 14
import { createSqlmancerClient } from "sqlmancer";
import { SqlmancerClient } from "./generated";
const client = createSqlmancerClient<SqlmancerClient>(__filename, knex);
@danielrearden
danielrearden / sqlmancer.sh
Created May 15, 2020 04:14
Making GraphQL Magic with Sqlmancer - 13
sqlmancer generate ./some/glob/**/*.graphql ./generated.ts
@danielrearden
danielrearden / query.graphql
Created May 15, 2020 04:13
Making GraphQL Magic with Sqlmancer - 12
query {
customers(
where: { firstName: { like: "L%" } }
orderBy: [{ invoices: { sum: { total: DESC } } }]
limit: 5
) {
id
firstName
lastName
invoices(
@danielrearden
danielrearden / index.ts
Created May 15, 2020 04:13
Making GraphQL Magic with Sqlmancer - 11
const apollo = new ApolloServer({ schema })