Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(replication): adds read replica functionality #430

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions examples/12-replica-db-connection/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
NODE_ENV=development
PGUSER=postgres
WARTHOG_APP_HOST=localhost
WARTHOG_APP_PORT=4100
WARTHOG_DB_DATABASE=warthog-example-12
WARTHOG_DB_USERNAME=postgres
WARTHOG_DB_PASSWORD=
WARTHOG_DB_SYNCHRONIZE=true
WARTHOG_DB_HOST=localhost
WARTHOG_DB_PORT=5432
WARTHOG_DB_REPLICA_HOST=localhost
WARTHOG_DB_REPLICA_PORT=5432
WARTHOG_DB_REPLICA_DATABASE=warthog-example-12
WARTHOG_DB_REPLICA_USERNAME=postgres
WARTHOG_DB_REPLICA_PASSWORD=
20 changes: 20 additions & 0 deletions examples/12-replica-db-connection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Example 12

## Setup

Run `yarn bootstrap && yarn start`

## Bootstrapping the App

Running `DEBUG=* yarn bootstrap` will do the following:

- Install packages
- Create the example DB
- Seed the database with test data

## Running the App

To run the project, run `yarn start`. This will:

- Run the API server
- Open GraphQL Playground
217 changes: 217 additions & 0 deletions examples/12-replica-db-connection/generated/binding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
import 'graphql-import-node'; // Needed so you can import *.graphql files

import { makeBindingClass, Options } from 'graphql-binding'
import { GraphQLResolveInfo, GraphQLSchema } from 'graphql'
import { IResolvers } from 'graphql-tools/dist/Interfaces'
import * as schema from './schema.graphql'

export interface Query {
users: <T = Array<User>>(args: { offset?: Int | null, limit?: Int | null, where?: UserWhereInput | null, orderBy?: UserOrderByInput | null }, info?: GraphQLResolveInfo | string, options?: Options) => Promise<T> ,
usersFromMaster: <T = Array<User>>(args?: {}, info?: GraphQLResolveInfo | string, options?: Options) => Promise<T> ,
user: <T = User>(args: { where: UserWhereUniqueInput }, info?: GraphQLResolveInfo | string, options?: Options) => Promise<T>
}

export interface Mutation {
createUser: <T = User>(args: { data: UserCreateInput }, info?: GraphQLResolveInfo | string, options?: Options) => Promise<T> ,
updateUser: <T = User>(args: { data: UserUpdateInput, where: UserWhereUniqueInput }, info?: GraphQLResolveInfo | string, options?: Options) => Promise<T> ,
deleteUser: <T = StandardDeleteResponse>(args: { where: UserWhereUniqueInput }, info?: GraphQLResolveInfo | string, options?: Options) => Promise<T>
}

export interface Subscription {}

export interface Binding {
query: Query
mutation: Mutation
subscription: Subscription
request: <T = any>(query: string, variables?: {[key: string]: any}) => Promise<T>
delegate(operation: 'query' | 'mutation', fieldName: string, args: {
[key: string]: any;
}, infoOrQuery?: GraphQLResolveInfo | string, options?: Options): Promise<any>;
delegateSubscription(fieldName: string, args?: {
[key: string]: any;
}, infoOrQuery?: GraphQLResolveInfo | string, options?: Options): Promise<AsyncIterator<any>>;
getAbstractResolvers(filterSchema?: GraphQLSchema | string): IResolvers;
}

export interface BindingConstructor<T> {
new(...args: any[]): T
}

export const Binding = makeBindingClass<BindingConstructor<Binding>>({ schema: schema as any })

/**
* Types
*/

export type UserOrderByInput = 'createdAt_ASC' |
'createdAt_DESC' |
'updatedAt_ASC' |
'updatedAt_DESC' |
'deletedAt_ASC' |
'deletedAt_DESC' |
'firstName_ASC' |
'firstName_DESC' |
'lastName_ASC' |
'lastName_DESC'

export interface BaseWhereInput {
id_eq?: String | null
id_in?: String[] | String | null
createdAt_eq?: String | null
createdAt_lt?: String | null
createdAt_lte?: String | null
createdAt_gt?: String | null
createdAt_gte?: String | null
createdById_eq?: String | null
updatedAt_eq?: String | null
updatedAt_lt?: String | null
updatedAt_lte?: String | null
updatedAt_gt?: String | null
updatedAt_gte?: String | null
updatedById_eq?: String | null
deletedAt_all?: Boolean | null
deletedAt_eq?: String | null
deletedAt_lt?: String | null
deletedAt_lte?: String | null
deletedAt_gt?: String | null
deletedAt_gte?: String | null
deletedById_eq?: String | null
}

export interface UserCreateInput {
firstName: String
lastName: String
}

export interface UserUpdateInput {
firstName?: String | null
lastName?: String | null
}

export interface UserWhereInput {
id_eq?: ID_Input | null
id_in?: ID_Output[] | ID_Output | null
createdAt_eq?: DateTime | null
createdAt_lt?: DateTime | null
createdAt_lte?: DateTime | null
createdAt_gt?: DateTime | null
createdAt_gte?: DateTime | null
createdById_eq?: ID_Input | null
createdById_in?: ID_Output[] | ID_Output | null
updatedAt_eq?: DateTime | null
updatedAt_lt?: DateTime | null
updatedAt_lte?: DateTime | null
updatedAt_gt?: DateTime | null
updatedAt_gte?: DateTime | null
updatedById_eq?: ID_Input | null
updatedById_in?: ID_Output[] | ID_Output | null
deletedAt_all?: Boolean | null
deletedAt_eq?: DateTime | null
deletedAt_lt?: DateTime | null
deletedAt_lte?: DateTime | null
deletedAt_gt?: DateTime | null
deletedAt_gte?: DateTime | null
deletedById_eq?: ID_Input | null
deletedById_in?: ID_Output[] | ID_Output | null
firstName_eq?: String | null
firstName_contains?: String | null
firstName_startsWith?: String | null
firstName_endsWith?: String | null
firstName_in?: String[] | String | null
lastName_eq?: String | null
lastName_contains?: String | null
lastName_startsWith?: String | null
lastName_endsWith?: String | null
lastName_in?: String[] | String | null
}

export interface UserWhereUniqueInput {
id: ID_Output
}

export interface BaseGraphQLObject {
id: ID_Output
createdAt: DateTime
createdById: String
updatedAt?: DateTime | null
updatedById?: String | null
deletedAt?: DateTime | null
deletedById?: String | null
version: Int
}

export interface DeleteResponse {
id: ID_Output
}

export interface BaseModel extends BaseGraphQLObject {
id: ID_Output
createdAt: DateTime
createdById: String
updatedAt?: DateTime | null
updatedById?: String | null
deletedAt?: DateTime | null
deletedById?: String | null
version: Int
}

export interface BaseModelUUID extends BaseGraphQLObject {
id: ID_Output
createdAt: DateTime
createdById: String
updatedAt?: DateTime | null
updatedById?: String | null
deletedAt?: DateTime | null
deletedById?: String | null
version: Int
}

export interface PageInfo {
hasNextPage: Boolean
hasPreviousPage: Boolean
startCursor?: String | null
endCursor?: String | null
}

export interface StandardDeleteResponse {
id: ID_Output
}

export interface User extends BaseGraphQLObject {
id: ID_Output
createdAt: DateTime
createdById: String
updatedAt?: DateTime | null
updatedById?: String | null
deletedAt?: DateTime | null
deletedById?: String | null
version: Int
firstName: String
lastName: String
}

/*
The `Boolean` scalar type represents `true` or `false`.
*/
export type Boolean = boolean

/*
The javascript `Date` as string. Type represents date and time as the ISO Date string.
*/
export type DateTime = Date | string

/*
The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.
*/
export type ID_Input = string | number
export type ID_Output = string

/*
The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
*/
export type Int = number

/*
The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
*/
export type String = string
Loading