Skip to content

Commit

Permalink
fix(gboost-infra): add data src to user-mgmt queries
Browse files Browse the repository at this point in the history
  • Loading branch information
bestickley committed Feb 15, 2022
1 parent 0ae127d commit 1b3e580
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-paws-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gboost-infra": patch
---

Add build script to include vtl, reference correct file ext for lambda entry points, correct gql api schema creation with user data source
5 changes: 5 additions & 0 deletions .changeset/warm-pots-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gboost": patch
---

Fix typo in \_templates
34 changes: 23 additions & 11 deletions packages/gboost-infra/src/user-management/createSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
ResolvableField,
EnumType,
Directive,
BaseDataSource,
} from "@aws-cdk/aws-appsync-alpha";
import { groupNames, adminGroupNames } from "./function/group.js";

export function createSchema(api: GraphqlApi) {
export function createSchema(api: GraphqlApi, dataSource: BaseDataSource) {
// Enum Types
const groupNameEnum = new EnumType("GroupNameEnum", {
definition: groupNames,
Expand Down Expand Up @@ -119,112 +120,123 @@ export function createSchema(api: GraphqlApi) {
api.addQuery(
"getUser",
new ResolvableField({
returnType: userType.attribute(),
args: { username: GraphqlType.string({ isRequired: true }) },
dataSource,
returnType: userType.attribute(),
})
);
api.addQuery(
"listGroupsForUser",
new ResolvableField({
args: { username: GraphqlType.string({ isRequired: true }) },
dataSource,
returnType: groupType.attribute({
isRequired: true,
isRequiredList: true,
isList: true,
}),
args: { username: GraphqlType.string({ isRequired: true }) },
})
);
api.addQuery(
"listGroups",
new ResolvableField({
dataSource,
returnType: groupConnection.attribute({ isRequired: true }),
})
);
api.addQuery(
"listUsersInGroup",
new ResolvableField({
returnType: userConnection.attribute({ isRequired: true }),
args: { input: listUsersInGroupInput.attribute() },
dataSource,
returnType: userConnection.attribute({ isRequired: true }),
})
);
api.addQuery(
"listUsers",
new ResolvableField({
returnType: userConnection.attribute({ isRequired: true }),
args: { input: listUsersInput.attribute() },
dataSource,
returnType: userConnection.attribute({ isRequired: true }),
})
);

// Mutations
api.addMutation(
"createUser",
new ResolvableField({
returnType: userType.attribute({ isRequired: true }),
args: { input: createUserInput.attribute() },
dataSource,
returnType: userType.attribute({ isRequired: true }),
})
);
api.addMutation(
"deleteUsers",
new ResolvableField({
returnType: GraphqlType.string(),
args: {
usernames: GraphqlType.string({
isRequired: true,
isList: true,
isRequiredList: true,
}),
},
dataSource,
directives: [Directive.cognito(...adminGroupNames)],
returnType: GraphqlType.string(),
})
);
api.addMutation(
"disableUsers",
new ResolvableField({
returnType: GraphqlType.string(),
args: {
usernames: GraphqlType.string({
isRequired: true,
isList: true,
isRequiredList: true,
}),
},
dataSource,
directives: [Directive.cognito(...adminGroupNames)],
returnType: GraphqlType.string(),
})
);
api.addMutation(
"enableUsers",
new ResolvableField({
returnType: GraphqlType.string(),
args: {
usernames: GraphqlType.string({
isRequired: true,
isList: true,
isRequiredList: true,
}),
},
dataSource,
directives: [Directive.cognito(...adminGroupNames)],
returnType: GraphqlType.string(),
})
);
api.addMutation(
"resetPasswords",
new ResolvableField({
returnType: GraphqlType.string(),
args: {
usernames: GraphqlType.string({
isRequired: true,
isList: true,
isRequiredList: true,
}),
},
dataSource,
directives: [Directive.cognito(...adminGroupNames)],
returnType: GraphqlType.string(),
})
);
api.addMutation(
"updateUser",
new ResolvableField({
returnType: GraphqlType.string(),
args: { input: updateUserInput.attribute() },
dataSource,
directives: [Directive.cognito(...groupNames)],
returnType: GraphqlType.string(),
})
);
}
2 changes: 1 addition & 1 deletion packages/gboost-infra/src/user-management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class UserManagement extends Construct {
});

const userDs = api.addLambdaDataSource("UserFn", userFn);
createSchema(api);
createSchema(api, userDs);
const resolverConfigs = [
{
fieldName: "getUser",
Expand Down

0 comments on commit 1b3e580

Please sign in to comment.