-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: graphql basic query and mutation
- Loading branch information
Showing
24 changed files
with
157 additions
and
59 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
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
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,16 @@ | ||
'use strict'; | ||
|
||
class BaseConnector { | ||
constructor(ctx) { | ||
this.ctx = ctx; | ||
} | ||
|
||
getSequelizeJSON(param = {}) { | ||
const { ctx } = this; | ||
const { page = {}, filter = {} } = param; | ||
|
||
return ctx.helper.parseSequelizeJSON(page, filter); | ||
} | ||
} | ||
|
||
module.exports = BaseConnector; |
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,7 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
__resolveType(data) { | ||
return data.typename; | ||
}, | ||
}; |
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 |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
|
||
module.exports = { | ||
Date: require('./scalars/date'), | ||
|
||
Datable: require('./interfaces/datable'), | ||
}; |
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
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 |
---|---|---|
|
@@ -5,4 +5,6 @@ type Group implements Datable { | |
name: String! | ||
create_time: Date! | ||
update_time: Date | ||
|
||
roles: [Role]! | ||
} |
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,3 @@ | ||
type Mutation { | ||
createApp(data: AppEntity!): MutationResponse | ||
} |
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,16 +1,19 @@ | ||
type Query { | ||
app(id: ID!): App | ||
apps: [App]! | ||
apps(param: SearchParam): [App]! | ||
|
||
group(id: ID!): Group | ||
groups(appId: Int): [Group]! | ||
groups(param: SearchParam): [Group]! | ||
|
||
role(id: ID!): Role | ||
roles(appId: Int, groupId: Int): [Role]! | ||
roles(param: SearchParam): [Role]! | ||
|
||
resourceType(id: ID!): ResourceType | ||
resourceTypes(param: SearchParam): [ResourceType]! | ||
|
||
resource(id: ID!): Resource | ||
resources(appId: Int, roleId: Int): [Resource]! | ||
resources(param: SearchParam): [Resource]! | ||
|
||
user(id: ID!): User | ||
users: [User]! | ||
users(param: SearchParam): [User]! | ||
} |
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
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,28 @@ | ||
'use strict'; | ||
|
||
const DataLoader = require('dataloader'); | ||
const BaseConnector = require('../base/connector'); | ||
|
||
class ResourceTypeConnector extends BaseConnector { | ||
constructor(ctx) { | ||
super(ctx); | ||
this.loaders = { | ||
resourceTypeIdLoader: new DataLoader(this.getByIds.bind(this)), | ||
}; | ||
} | ||
|
||
getByIds(ids) { | ||
return this.ctx.app.model.ResourceType.findByIds(ids); | ||
} | ||
|
||
getById(id) { | ||
return this.loaders.resourceTypeIdLoader.load(id); | ||
} | ||
|
||
getAll(param) { | ||
const sequelizeJSON = this.getSequelizeJSON(param); | ||
return this.ctx.app.model.ResourceType.findAll(sequelizeJSON); | ||
} | ||
} | ||
|
||
module.exports = ResourceTypeConnector; |
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,12 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
Query: { | ||
resourceType(root, { id }, ctx) { | ||
return ctx.connector.resourcetype.getById(id); | ||
}, | ||
resourceTypes(root, { param }, ctx) { | ||
return ctx.connector.resourcetype.getAll(param); | ||
}, | ||
}, | ||
}; |
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,9 @@ | ||
type ResourceType implements Datable { | ||
id: ID! | ||
code: String! | ||
name: String! | ||
create_time: Date! | ||
update_time: Date | ||
|
||
resources: [Resource]! | ||
} |
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
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 |
---|---|---|
|
@@ -5,4 +5,6 @@ type Role implements Datable { | |
name: String! | ||
create_time: Date! | ||
update_time: Date | ||
|
||
resources: [Resource]! | ||
} |
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
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