-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update way to get query resolvers and schema
- Loading branch information
1 parent
f62591d
commit 3dccbe7
Showing
8 changed files
with
88 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
import { gql } from 'apollo-server-express'; | ||
import { DocumentNode } from "graphql"; | ||
|
||
const typeDefs = gql` | ||
scalar Date | ||
import * as glob from "glob"; | ||
import * as path from "path"; | ||
import { gql } from "apollo-server-express"; | ||
|
||
const queries = []; | ||
|
||
let queryFiles = glob | ||
.sync(path.resolve(__dirname, "./resolvers/Query/*.ts")) | ||
.map((p) => path.basename(p)); | ||
|
||
type Query { | ||
me: User | ||
} | ||
queryFiles.forEach((queryFile) => { | ||
const Query = require(`./resolvers/Query/${queryFile}`).default; // eslint-disable-line global-require,import/no-dynamic-require | ||
queries.push(Query); | ||
}); | ||
|
||
type User { | ||
example: String! | ||
} | ||
const rootQuery = gql` | ||
scalar Date | ||
`; | ||
|
||
export default [typeDefs]; | ||
export const queryTypeDefs: Array<DocumentNode> = [rootQuery]; | ||
|
||
queries.forEach((q) => { | ||
queryTypeDefs.push(q.typeDef); | ||
}); | ||
|
||
export default queryTypeDefs; |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import errors from '../../../errors'; | ||
export default { | ||
name: "me", | ||
typeDef: ` | ||
type Query { | ||
me: User | ||
} | ||
export default async (_, args, { dataSources }) => { | ||
|
||
return dataSources.User.me(); | ||
type User { | ||
example: String! | ||
} | ||
`, | ||
query: ` | ||
me: User | ||
`, | ||
resolver: async (_, args, { dataSources }) => { | ||
return dataSources.User.me(); | ||
}, | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
name: "example", | ||
resolver: async (user, args, { dataSources }) => { | ||
return user.example + "_WithResolver"; | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
import * as chai from 'chai'; | ||
import * as sinon from 'sinon'; | ||
import * as chai from "chai"; | ||
import * as sinon from "sinon"; | ||
|
||
import meResolver from '../../../src/schema/resolvers/Query/me'; | ||
import meResolver from "../../../src/schema/resolvers/Query/me"; | ||
|
||
const { expect } = chai; | ||
|
||
describe('[resolver] Query { me() }', () => { | ||
it('Should pass me', async () => { | ||
describe("[resolver] Query { me() }", () => { | ||
it("Should pass me", async () => { | ||
const dataSources = { | ||
User: { | ||
me: sinon.stub().returns({ data: { user: {example: 'example'} } }), | ||
me: sinon.stub().returns({ data: { user: { example: "example" } } }), | ||
}, | ||
}; | ||
const args = null; | ||
|
||
const spyCall = await meResolver(null, args, { dataSources }); | ||
expect(JSON.stringify(spyCall)).to.be.equals(JSON.stringify({"data":{"user":{"example": "example"}}})); | ||
const spyCall = await meResolver.resolver(null, args, { dataSources }); | ||
expect(JSON.stringify(spyCall)).to.be.equals( | ||
JSON.stringify({ data: { user: { example: "example" } } }) | ||
); | ||
}); | ||
}); |