This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isSuccess(success) { | |
return new Promise(function (resolve, reject) { | |
if (success === true) { | |
resolve('Success'); | |
} else { | |
reject('Error'); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |