graphql-shortcake
v1.4.12
Published
#### Class
Downloads
11
Readme
GraphQL Shortcake
Class
- Model
- GlobalModel
- Client
- Row
- buildDataSources
Preset Method
- witholumn
- withBuilder
- withLoader
- withFetcher
- withMutator
- withBatch
- withDefaultValues
- withGlobalId
- withDataSources
Option Method
- withSearcher
- withArrayMutator
- withJSONMutator
- withIncrementer
Use Case
Sample Code
const client = new Client({
host: '127.0.0.1',
user: 'postgres',
password: null,
database: 'graphql_shortcake',
});
class User extends Model {
static client = client;
static tableName = 'user';
static columns = {
name: { type: String },
}
}
const user = new User({ name: 'Apple Pie' });
await user.save();
Sample Code with Apollo Schema
const client = new Client({
host: '127.0.0.1',
user: 'postgres',
password: null,
database: 'graphql_shortcake',
});
class User extends GlobalModel {
static client = client;
static tableName = 'user';
static columns = {
name: { type: String },
}
}
class Book extends GlobalModel {
static client = client;
static tableName = 'book';
static columns = {
name: { type: String },
}
}
const DataSources = buildDataSources({
UR: User,
BK: Book,
});
const server = new ApolloServer(
dataSources: () => new DataSources(),
});
Use mock
import { mock } from "graphql-shortcake";
const client = jest.requireActual("../client").default;
const mockClient = mock(client);
export default mockClient;
Column List
- String
- Number
- Boolean
- String
- Hash
- Model
- Mixed
- Expiratoin
- DateTime.Dater
- DateTime.Timer
- DateTime
- Enum
DataSources
const { User } = dataSources;
const { fetcher } = User;
fetcher.onFetch = dataSources.mount;
const { user } = dataSources;
const user = new User({}, { dataSources });
const user = dataSources.loadUser(id);
const model = await User.load(id);
const user = Model.forge(model.previous, { dataSources });