added mock tenant api

This commit is contained in:
Wyatt Johnson
2018-06-16 17:59:21 -06:00
parent 4318e1ddbe
commit 7177988059
9 changed files with 110 additions and 11 deletions
@@ -0,0 +1,13 @@
import { Db } from 'mongodb';
export interface ContextOptions {
db: Db;
}
export default class TenantContext {
public db: Db;
constructor({ db }: ContextOptions) {
this.db = db;
}
}
@@ -0,0 +1,12 @@
import { graphqlExpress } from 'apollo-server-express';
import schema from './schema';
import Context from './context';
import { Db } from 'mongodb';
export default (db: Db) =>
graphqlExpress(async req => {
return {
schema,
context: new Context({ db }),
};
});
@@ -0,0 +1,18 @@
import { addMockFunctionsToSchema } from 'graphql-tools';
import { getGraphQLProjectConfig } from 'graphql-config';
// Load the configuration from the provided `.graphqlconfig` file.
const config = getGraphQLProjectConfig(__dirname, 'management');
// Get the GraphQLSchema from the configuration.
const schema = config.getSchema();
// Attach resolvers to the schema.
addMockFunctionsToSchema({
schema,
mocks: {
Cursor: () => new Date().toISOString(),
},
}); // FIXME: remove mocks
export default schema;
@@ -0,0 +1,39 @@
################################################################################
## Custom Scalar Types
################################################################################
"""
Time represented as an ISO8601 string.
"""
scalar Time
"""
Cursor represents a paginating cursor.
"""
scalar Cursor
################################################################################
## Tenant
################################################################################
type Tenant {
id: ID!
"""
organizationName is the name of the organization.
"""
organizationName: String
"""
organizationContactEmail is the email of the organization.
"""
organizationContactEmail: String
}
################################################################################
## Query
################################################################################
type Query {
tenant(id: ID!): Tenant
}
@@ -1,6 +1,6 @@
import Asset from './asset';
import Comment from './comment';
import Cursor from './cursor';
import Cursor from '../../common/scalars/cursor';
import Query from './query';
export default {
+1 -9
View File
@@ -2,7 +2,7 @@ import {
addMockFunctionsToSchema,
addResolveFunctionsToSchema,
} from 'graphql-tools';
import resolvers from 'talk-server/graph/tenant/resolvers';
import resolvers from '../resolvers';
import { getGraphQLProjectConfig } from 'graphql-config';
// Load the configuration from the provided `.graphqlconfig` file.
@@ -14,12 +14,4 @@ const schema = config.getSchema();
// Attach the resolvers to the schema.
addResolveFunctionsToSchema({ schema, resolvers });
// // Attach resolvers to the schema.
// addMockFunctionsToSchema({
// schema,
// mocks: {
// Cursor: () => new Date().toISOString(),
// },
// }); // FIXME: remove mocks
export default schema;