parent
ffb09ba73b
commit
b88925f065
@ -0,0 +1,4 @@ |
||||
module.exports = { |
||||
preset: 'ts-jest', |
||||
testEnvironment: 'node', |
||||
}; |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,22 @@ |
||||
import { callSchema } from "../callSchema"; |
||||
|
||||
const usersQuery = ` |
||||
query { |
||||
users { |
||||
id |
||||
} |
||||
}` |
||||
|
||||
describe("user resolver", () => { |
||||
it("should return an empty array when no users are in sample", async () => { |
||||
const response = await callSchema({ |
||||
source: usersQuery, |
||||
}) |
||||
|
||||
expect(response).toMatchObject({ |
||||
data: { |
||||
users: [], |
||||
}, |
||||
}) |
||||
}) |
||||
}) |
@ -1,13 +1,13 @@ |
||||
import "reflect-metadata" |
||||
import { Resolver, Query } from "type-graphql" |
||||
import { User } from "../User" |
||||
import "reflect-metadata"; |
||||
import { Query, Resolver } from "type-graphql"; |
||||
import { User } from "../User"; |
||||
|
||||
@Resolver() |
||||
export class UserResolver { |
||||
private recipesCollection: User[] = [] |
||||
private usersCollection: User[] = [] |
||||
|
||||
@Query(returns => [User]) |
||||
async users() { |
||||
return await this.recipesCollection |
||||
return await this.usersCollection |
||||
} |
||||
} |
||||
|
@ -0,0 +1,18 @@ |
||||
import { graphql, GraphQLSchema } from "graphql" |
||||
import { createSchema } from "./createSchema" |
||||
|
||||
interface Options { |
||||
source: string |
||||
} |
||||
|
||||
let schema: GraphQLSchema |
||||
|
||||
export const callSchema = async ({ source }: Options) => { |
||||
if (!schema) { |
||||
schema = await createSchema() |
||||
} |
||||
return graphql({ |
||||
schema, |
||||
source, |
||||
}) |
||||
} |
@ -0,0 +1,7 @@ |
||||
import { buildSchema } from "type-graphql"; |
||||
import { UserResolver } from "./User/UserResolver"; |
||||
|
||||
export const createSchema = () => |
||||
buildSchema({ |
||||
resolvers: [UserResolver], |
||||
}) |
Loading…
Reference in new issue