Commit Graph

63 Commits

Author SHA1 Message Date
Igor 0f46886880 Added submodule links to Submodule type in GraphQL API
This is part of migration of Folder View to Vue
2019-07-17 13:06:19 +00:00
Luke Duncalfe 073c8b25ea GraphQL support for Notes created in discussions
A new `discussion_id` argument on the `createNote` mutation allows
people to create a note within that discussion.

The ability to lazy-load Discussions has been added, so
GraphQL.object_from_id can treat Discussions the same as AR objects and
batch load them.

https://gitlab.com/gitlab-org/gitlab-ce/issues/62826
https://gitlab.com/gitlab-org/gitlab-ee/issues/9489
2019-07-10 12:13:48 +12:00
Luke Duncalfe 254f78f5dc Expose diff_refs on MergeRequestType
https://gitlab.com/gitlab-org/gitlab-ee/issues/9489
2019-07-10 12:13:48 +12:00
charlieablett 675c9b9f6b Address reviewer comments
- Remove Gitaly call check for fields that have a constant complexity
declared
- Add associated test
2019-07-05 10:18:50 +12:00
charlieablett cf1b0d10bc Address reviewer comments
- Add 1 for all fields that call Gitaly (with resolvers or without)
- Clarify comment regarding Gitaly call alert
- Expose predicate `calls_gitaly?` instead of ivar
2019-07-03 22:53:13 +12:00
charlieablett f4890d9078 Alert if `calls_gitaly` declaration missing
- Move `calls_gitaly_check` to public
- Add instrumentation for flagging missing CallsGitaly declarations
- Wrap resolver proc in before-and-after Gitaly counts to get the net
Gitaly call count for the resolver.
2019-07-03 22:53:13 +12:00
charlieablett c99c30fdd6 Remove potentially noisy warning
- If Gitaly calls are missing, it could be due to a conditional and
may just become noise
2019-07-03 22:53:13 +12:00
charlieablett 8b809837f4 Enumerate fields with Gitaly calls
- Add a complexity of 1 if Gitaly is called at least once
 - Add an error notification if `calls_gitaly` isn't right for a
 particular field
2019-07-03 22:53:13 +12:00
Marin Jankovski c20c9e2940
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce 2019-07-03 11:55:56 +02:00
Lin Jen-Shin 2321b337f1 Merge branch 'graphql-tree-last-commit' into 'master'
Added commit type to tree GraphQL type

See merge request gitlab-org/gitlab-ce!29412
2019-06-28 10:02:57 +00:00
Phil Hughes d78f7ceac9
Added commit type to tree GraphQL type 2019-06-28 08:30:29 +01:00
Luke Duncalfe 4b9b2a43d0 GraphQL mutations for add, remove and toggle emoji
Adding new `AddAwardEmoji`, `RemoveAwardEmoji` and `ToggleAwardEmoji`
GraphQL mutations.

Adding new `#authorized_find_with_pre_checks!` and (unused, but for
completeness `#authorized_find_with_post_checks!`) authorization
methods. These allow us to perform an authorized find, and run our own
additional checks before or after the authorization runs.

https://gitlab.com/gitlab-org/gitlab-ce/issues/62826
2019-06-28 12:03:33 +12:00
Bob Van Landuyt 703d0246ff Add authorize to LabelType and NamespaceType
This also disables the cop with a reasoning in types where appropriate
2019-06-21 13:00:50 +02:00
Bob Van Landuyt 406808583c Render GFM html in GraphQL
This adds a `markdown_field` to our types.

Using this helper will render a model's markdown field using the
existing `MarkupHelper` with the context of the GraphQL query
available to the helper.

Having the context available to the helper is needed for redacting
links to resources that the current user is not allowed to see.

Because rendering the HTML can cause queries, the complexity of a
these fields is raised by 5 above the default.

The markdown field helper can be used as follows:

      ```
      markdown_field :note_html, null: false
      ```

This would generate a field that will render the markdown field `note`
of the model. This could be overridden by adding the `method:`
argument. Passing a symbol for the method name:

      ```
      markdown_field :body_html, null: false, method: :note
      ```

It will have this description by default:

> The GitLab Flavored Markdown rendering of `note`

This could be overridden by passing a `description:` argument.

The type of a `markdown_field` is always `GraphQL::STRING_TYPE`.
2019-06-20 08:02:33 +00:00
Bob Van Landuyt b6ff5f1e14 Expose comments on Noteables in GraphQL
This exposes `Note`s on Issues & MergeRequests using a
`Types::Notes::NoteableType` in GraphQL.

Exposing notes on a new type can be done by implementing the
`NoteableType` interface on the type. The presented object should
be a `Noteable`.
2019-06-14 12:36:27 +02:00
Phil Hughes 522c01972c
Add LFS blob ID to GraphQL blob type 2019-06-10 09:05:44 +01:00
Jan Provaznik 9318fba9cb Merge branch '62706-graphql-complexity-values-are-incorrectly-doubled' into 'master'
Reduce GraphQL complexity for non-connection fields

Closes #62706

See merge request gitlab-org/gitlab-ce!29165
2019-06-06 11:54:30 +00:00
Nick Thomas 327c7d5a07 Merge branch 'graphql-file-entry-url' into 'master'
Add web_url to tree entry in GraphQL API

See merge request gitlab-org/gitlab-ce!28646
2019-06-05 15:44:53 +00:00
Brett Walker 95b3fe2863 Use :complexity_multiplier only with connections
This helps reduce complexity for non-connections
2019-06-05 10:17:54 -05:00
Jan Provaznik d9a761ed14 Merge branch 'bvl-use-global-ids-graphql' into 'master'
Use global IDs when exposing GraphQL resources

Closes #62650

See merge request gitlab-org/gitlab-ce!29080
2019-06-05 10:25:22 +00:00
Phil Hughes 4644a2daf5
Add web_url to tree entry in GraphQL API 2019-06-05 08:46:32 +01:00
Alessio Caiazza 4e251d01de Expose wiki_size on GraphQL API 2019-06-04 12:11:41 +00:00
Bob Van Landuyt ed503d51a3 Expose IDs in GraphQL as a GlobalID
This exposes all fields named `id` as GlobalIDs so they can be used
across our entire GraphQL implementation.

When the objects loaded are `ApplicationRecord`s. We'll use our
existing batchloading to find them. Otherwise, we'll fall back to the
default implementation of `GlobalID`: Calling the `.find` method on
the class.
2019-06-03 21:59:25 +02:00
Alessio Caiazza 83a8b77961 Add Namespace and ProjectStatistics to GraphQL API
We can query namespaces, and nested projects.

Projects now exposes statistics
2019-06-03 12:01:32 +02:00
Brett Walker 1285b00517 Added common fields to the IssueType
and allow passing of child_complexity to the
'resolver_complexity' metho
2019-05-31 13:19:29 -05:00
Phil Hughes 11f85ae8c3 Enables GraphQL batch requests
Enabling GraphQL batch requests allows for multiple queries
to be sent in 1 request reducing the amount of requests
we send to the server.

Responses come come back in the same order as the queries were
provided.
2019-05-28 10:22:02 +02:00
Nick Thomas 454cbac3ef Merge branch 'graphql-tree' into 'master'
Added repository files to GraphQL API

See merge request gitlab-org/gitlab-ce!28325
2019-05-22 15:06:03 +00:00
Phil Hughes 67a5086195
Added repository files to GraphQL API 2019-05-22 12:43:35 +01:00
Brett Walker 0f14b628c4 Use BatchModelLoader for parent in GroupType 2019-05-20 17:23:11 -05:00
Sean McGivern 9f888c7440 Merge branch '58404-set-default-max-depth-for-GraphQL' into 'master'
58404 - setup max depth for graphql

Closes #58404

See merge request gitlab-org/gitlab-ce!25737
2019-05-08 08:46:56 +00:00
Jan Provaznik 5ee7884d91 GraphQL - Add extra complexity for resolvers
If a field is a resolver, its complexity is automatically
increased. By default we add extra points for sort and search
arguments (which will be common for various resolvers).

For specific resolvers we add field-specific complexity, e.g.
for Issues complexity is increased if we filter issues by `labelName`
(because then SQL query is more complex). We may want to tune these
values in future depending on real-life results.

Complexity is also dependent on the number of loaded nodes, but only
if we don't search by specific ID(s). Also added complexity is limited
(by default only twice more than child complexity) - the reason is
that although it's more complex to process more items, the complexity
increase is not linear (there is not so much difference between loading
10, 20 or 100 records from DB).
2019-05-06 21:24:19 +00:00
Ken Ding f80f68d520 58404 - setup max depth for graphql
58404 - add change log


58404 - add spec


58404 - add more spec to test depth 2


58404 - fix spec


58404 - fix rubocop


58404 - refactor the code by Bob's advice


58404 - revert changes of all_graphql_fields_for


58404 - change text only


58404 - fix rspec according to gitlab's standard


58404 - revert previous spec


58404 - fix rubocop
2019-05-07 00:32:29 +09:30
Grzegorz Bizon 1911521043 Merge branch 'bw-add-graphql-groups' into 'master'
Add basic GraphQL for a Group

Closes #60786

See merge request gitlab-org/gitlab-ce!27492
2019-04-30 14:51:33 +00:00
Bob Van Landuyt 33cf8edae1 Port changes for design management to CE
This ports the changes from
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/10462/
to CE
2019-04-29 08:28:43 +02:00
Brett Walker f5c7c3b9ae Basic GraphQL for a group
Add new query for Groups, with new
GroupType and NamespaceType
2019-04-23 11:16:05 -05:00
Bob Van Landuyt eca8e6f09b Only check abilities on rendered GraphQL nodes
With this we only check abilities on the rendered edges of a GraphQL
connection instead of all the nodes in it.
2019-04-18 16:17:29 +02:00
Nick Thomas beeeede2ee
Fix a KeyError in GitlabSchema 2019-04-04 18:57:34 +01:00
Nick Thomas a2d044bf97 Merge branch '57831-allow-graphql-scalar-fields-to-be-authorized' into 'master'
Allow GraphQL Scalar-fields to be authorized

Closes #57831

See merge request gitlab-org/gitlab-ce!26338
2019-04-04 17:12:43 +00:00
Brett Walker 6643b92b88 Use parent object when authorizing scalar types 2019-04-04 09:03:21 -05:00
Brett Walker f458c56107 Initial field and query complexity limits
It makes all Types::BaseField default to a complexity of 1.

Queries themselves now have limited complexity, scaled
to the type of user: no user, authenticated user, or an
admin user.
2019-04-04 08:39:30 -05:00
Luke Duncalfe 8207f7877f GraphQL Type authorization
Enables authorizations to be defined on GraphQL Types.

    module Types
      class ProjectType < BaseObject
        authorize :read_project
      end
    end

If a field has authorizations defined on it, and the return type of the
field also has authorizations defined on it. then all of the combined
permissions in the authorizations will be checked and must pass.

Connection fields are checked by "digging" to find the type class of the
"node" field in the expected location of edges->node.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/54417
2019-04-03 14:36:33 +13:00
Bob Van Landuyt e756dca0c5 Extra permissions in Project & Issue GraphQL
Allow extra permissions for the `Types::ProjectType` and
`Types:IssueType` GraphQL types. As we'll be adding more permissions
in CE.

Now this spec only validates if all the expected permissions are
present, but it will not fail if there are more.
2019-04-01 10:55:33 +02:00
Sam Bigelow 1a14e5230e Add merge request popover with details
- Show pipeline status, title, MR Status and project path
- Popover attached to gitlab flavored markdown everywhere, including:
  + MR/Issue Title
  + MR/Issue description
  + MR/Issue comments
  + Rendered markdown files
2019-03-21 10:24:18 -04:00
Douwe Maan 01b1076bd8 Apply suggestion to spec/graphql/types/query_type_spec.rb 2019-03-05 15:46:00 +00:00
Nick Thomas 21779d0018
Add metadata about the GitLab server to GraphQL 2019-03-05 15:00:32 +00:00
Luke Duncalfe ccb4edbca1 Improve GraphQL Authorization DSL
Previously GraphQL field authorization happened like this:

    class ProjectType
      field :my_field, MyFieldType do
        authorize :permission
      end
    end

This change allowed us to authorize like this instead:

    class ProjectType
      field :my_field, MyFieldType, authorize: :permission
    end

A new initializer registers the `authorize` metadata keyword on GraphQL
Schema Objects and Fields, and we can collect this data within the
context of Instrumentation like this:

    field.metadata[:authorize]

The previous functionality of authorize is still being used for
mutations, as the #authorize method here is called at during the code
that executes during the mutation, rather than when a field resolves.

https://gitlab.com/gitlab-org/gitlab-ce/issues/57828
2019-02-26 10:22:12 +13:00
Rémy Coutable 87dfe5a27a
Add GraphQL filters for issuables (state, labels, time fields)
Signed-off-by: Rémy Coutable <remy@rymai.me>
2019-02-21 09:40:49 +01:00
Lin Jen-Shin 30918929ad Implement singular iid for IssuesResolver and ProjectType 2019-02-14 15:52:17 +08:00
Lin Jen-Shin 564b86a314 Allow authorize on array of objects for GraphQL
And add tests
2019-02-14 15:52:17 +08:00
Lin Jen-Shin 7be1f0842f Add tests for BaseResolver and update accordingly 2019-02-14 15:52:17 +08:00