예제 #1
0
        public ProjectsSpecification(ProjectCommonController projects)
        {
            var safe    = new Safe(_log);
            var options = new GraphQlQueryOptions <ProjectCommonController, ProjectModel, Project>(projects);

            Name = "Projects";
            Field <ProjectSpecification>(
                "byId",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "id",
                Description = "id of the project"
            }
                    ),
                resolve: safe.Wrap(context => projects.GetById(context.GetArgument <string>("id")))
                ).RequirePermission(Activity.ReadProject);
            Field <ListGraphType <ProjectSpecification> >(
                "all",
                Description = "all projects",
                resolve: safe.Wrap(context => projects.Query(queryable => queryable))
                ).RequirePermission(Activity.ReadProject);
            Field <ListGraphType <ProjectSpecification> >(
                "recent",
                Description = "recent modified projects",
                new QueryArguments(
                    new QueryArgument <IntGraphType>
            {
                Name        = "first",
                Description = "id of the project"
            }
                    ),
                safe.Wrap(context => projects
                          .Query(queryable =>
                                 queryable
                                 .OrderByDescending(x => x.UpdateDate)
                                 .Take(context.HasArgument("first") ? context.GetArgument <int>("first") : 100)
                                 ))
                ).RequirePermission(Activity.ReadProject);
            Field <QueryResultSpecification>(
                "query",
                Description = "query the projects projects",
                options.GetArguments(),
                safe.Wrap(context => options.Query(context))
                ).RequirePermission(Activity.ReadProject);
        }
예제 #2
0
        public UsersSpecification(UserCommonController users)
        {
            var safe    = new Safe(_log);
            var options = new GraphQlQueryOptions <UserCommonController, UserModel, User>(users);

            Name = "Users";

            Field <UserSpecification>(
                "byId",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "id",
                Description = "id of the user"
            }
                    ),
                resolve: safe.Wrap(context => users.GetById(context.GetArgument <string>("id")))
                ).RequirePermission(Activity.ReadUsers);

            Field <ListGraphType <UserSpecification> >(
                "all",
                Description = "all users",
                resolve: context => users.Query(queryable => queryable)
                ).RequirePermission(Activity.ReadUsers);

            Field <ListGraphType <UserSpecification> >(
                "recent",
                Description = "recent modified users",
                new QueryArguments(
                    new QueryArgument <IntGraphType>
            {
                Name        = "first",
                Description = "id of the user"
            }
                    ),
                safe.Wrap(context => users
                          .Query(queryable =>
                                 queryable
                                 .OrderByDescending(x => x.UpdateDate)
                                 .Take(context.HasArgument("first") ? context.GetArgument <int>("first") : 100)
                                 ))
                ).RequirePermission(Activity.ReadUsers);

            Field <QueryResultSpecification>(
                "query",
                Description = "query the projects projects",
                options.GetArguments(),
                safe.Wrap(context => options.Query(context))
                ).RequirePermission(Activity.ReadUsers);


            Field <UserSpecification>(
                "me",
                Description = "Current user",
                resolve: safe.Wrap(context => Me(users))
                ).RequireAuthorization();


            Field <ListGraphType <RoleSpecification> >(
                "roles",
                Description = "All roles",
                resolve: safe.Wrap(context => users.Roles())
                );

            Field <RoleSpecification>(
                "role",
                Description = "All roles",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >
            {
                Name        = "name",
                Description = "role name"
            }
                    ),
                resolve: safe.Wrap(context => LookupRole(users, context.GetArgument <string>("name")))
                );
        }