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
@craicoverflow
craicoverflow / steps.md
Last active August 19, 2021 11:51
Switching environment using rhoas CLI

Add the following to your .bashrc|.bash_profile|.zshrc|.fishrc (or whatever you use).

function set_rhoas_env {
    local env=$1

    case $env in
        "stage")
            RHOASCONFIG="$HOME/.config/rhoas/config.stage.json"
 ;;
We couldn’t find that file to show.
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 {
@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
}
@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
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 / 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;

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 / 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"}
@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');
}
});
}