Skip to content

Instantly share code, notes, and snippets.

View danielrearden's full-sized avatar

Daniel Rearden danielrearden

View GitHub Profile
@danielrearden
danielrearden / index.ts
Created May 15, 2020 04:11
Making GraphQL Magic with Sqlmancer - 8
const { models: { Customer, Invoice } } = createSqlmancerClient(__filename, knex);
@danielrearden
danielrearden / index.ts
Created May 15, 2020 04:12
Making GraphQL Magic with Sqlmancer - 9
const resolvers = {
Query: {
customers: (root, args, ctx, info) => {
return Customer.findMany()
.resolveInfo(info)
.execute();
},
invoices: (root, args, ctx, info) => {
return Invoice.findMany()
.resolveInfo(info)
@danielrearden
danielrearden / index.ts
Created May 15, 2020 04:12
Making GraphQL Magic with Sqlmancer - 10
import { createSqlmancerClient, makeSqlmancerSchema } from "sqlmancer";
const schema = makeSqlmancerSchema({ typeDefs, resolvers });
@danielrearden
danielrearden / index.ts
Created May 15, 2020 04:13
Making GraphQL Magic with Sqlmancer - 11
const apollo = new ApolloServer({ schema })
@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 / sqlmancer.sh
Created May 15, 2020 04:14
Making GraphQL Magic with Sqlmancer - 13
sqlmancer generate ./some/glob/**/*.graphql ./generated.ts
@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 / 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 / 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 / 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;