Skip to content

Instantly share code, notes, and snippets.

View craicoverflow's full-sized avatar
🏠
Working from home

Enda craicoverflow

🏠
Working from home
View GitHub Profile

Add abstraction for ts/js generation in resolvers

Address all TODO's

Relationship support

Subscription support

Paggination support

@craicoverflow
craicoverflow / app.js
Last active November 19, 2019 14:23
JavaScript Async Example
function isSuccess(success) {
return new Promise(function (resolve, reject) {
if (success === true) {
resolve('Success');
} else {
reject('Error');
}
});
}
@craicoverflow
craicoverflow / cloudSettings
Last active March 2, 2020 08:30
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-01-15T14:46:00.870Z","extensionVersion":"v3.4.3"}

For a flexible relationship mapping system to work, we really only need two fields, along with the relationship type:

@oneToMany | @oneToOne | @manyToOne
    field: The field name on the opposite model to map to.
    column: The database column name on the opposite model to map to.

The field and column can be optional depending on what other metadata is provided. See Cases below for some examples.

@craicoverflow
craicoverflow / schemaTransformer.ts
Created March 4, 2020 08:35
Transform GraphQL Schema
import { GraphQLSchema, GraphQLObjectType, GraphQLField, buildSchema, GraphQLScalarType, GraphQLString, printSchema, GraphQLNamedType } from 'graphql';
const schema = buildSchema(`
type User {
id: ID!
name: String
}
`)
const userType = schema.getType('User') as GraphQLObjectType;
async function createModels(modelsDir: string, schema: GraphQLSchema, defaultDataProvider: GraphbackDataProvider, dbProviderOverrides: { [modelName: string]: GraphbackDataProvider } = {}, pubSub: PubSub): Promise<{ [serviceName: string]: CRUDService }> {
const models = require(modelsDir);
const modelsConfig = { ...models.modelConfigs };
delete models.modelConfigs;
const noteConfig = {
name: "Note",
pubSub: {
publishCreate: false,
@craicoverflow
craicoverflow / hybrid-runtime.ts
Last active April 7, 2020 14:27
Hybvrid runtime services
async function createModels(modelsDir: string, schema: GraphQLSchema, defaultDataProvider: GraphbackDataProvider, dbProviderOverrides: { [modelName: string]: GraphbackDataProvider } = {}, pubSub: PubSub): Promise<{ [serviceName: string]: CRUDService }> {
const models = require(modelsDir);
delete models.modelConfigs;
const services = {};
for (const modelName of Object.keys(models)) {
const modelType = schema.getType(modelName) as GraphQLObjectType
const dbProvider = dbProviderOverrides[modelName] || defaultDataProvider
@craicoverflow
craicoverflow / new-runtime-api.ts
Last active May 26, 2020 14:53
Pseudo-prototype of new runtime API
import { GraphbackDataProvider, GraphbackPlugin } from "graphback"
import { DocumentNode, GraphQLSchema } from 'graphql'
import { IResolvers, PubSubEngine } from 'apollo-server-express'
import { PgKnexDBDataProvider } from '@graphback/runtime-knex'
import Knex from 'knex'
interface DataProviderModelMap {
[modelName: string]: GraphbackDataProvider
}
import { GraphQLObjectType } from 'graphql';
import { NoDataError } from '@graphback/runtime';
import { getDatabaseArguments } from '@graphback/core';
import { ObjectId } from 'mongodb';
import { MongoDBDataProvider } from './MongoDBDataProvider';
enum GraphbackDirective {
UpdatedAt = 'updatedAt'
}
interface FieldDirectiveTransformer {
We couldn’t find that file to show.