Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Add Cody context filters to the site config and expose them via GraphQL#61101

Merged
taras-yemets merged 23 commits into
mainfrom
ty/add-cody-ignore-rules-to-site-config
Apr 15, 2024
Merged

Add Cody context filters to the site config and expose them via GraphQL#61101
taras-yemets merged 23 commits into
mainfrom
ty/add-cody-ignore-rules-to-site-config

Conversation

@taras-yemets

@taras-yemets taras-yemets commented Mar 13, 2024

Copy link
Copy Markdown
Contributor

Closes https://github.com/sourcegraph/sourcegraph/issues/61605

Adds Cody context filters to the site config and corresponding GraphQL resolvers.
The codyContextFilters query has a required version parameter to simplify future API evolution. Returns "cody.contextFilters" site config param value as JSON.

Example query

query {
    site {
	codyContextFilters(version: V1) {
            raw
        }
    }
}
"cody.contextFilters" in the site config Query result
Screenshot 2024-04-11 at 11 05 57 Screenshot 2024-04-11 at 11 06 05
Screenshot 2024-04-11 at 11 09 13 Screenshot 2024-04-11 at 11 09 20
not defined Screenshot 2024-04-11 at 11 11 00

Test plan

  • CI
  • Tested manually

@cla-bot cla-bot Bot added the cla-signed label Mar 13, 2024
@taras-yemets taras-yemets marked this pull request as ready for review April 5, 2024 08:46
@taras-yemets taras-yemets requested a review from a team April 5, 2024 08:46
@taras-yemets taras-yemets changed the title Add Cody Ignore rules to the site config Add Cody context filters to the site config and expose them via GraphQL Apr 5, 2024
@sourcegraph-bot

sourcegraph-bot commented Apr 5, 2024

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

@valerybugakov valerybugakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API console response before setting up the cody.contextFilters value locally. Should we return nulls without panic messages?

Screenshot 2024-04-08 at 12 09 24

@arafatkatze arafatkatze left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does what it claims to do(tested locally)

There is a longer goal with this PR for context inclusion/exclusion stuff etc so I don't grok the whole picture just yet but for now this PR does what it claims to do so 👍 from me

@chwarwick chwarwick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is worth a little extra time up front to make sure you get the schema right to lock down the behavior you want to enforce. Since there is some time until the next release you could still make breaking changes but it's nice to avoid those if possible.

Also probably worth noting that those resolvers/settings are experimental and eventually dependent on Client versions >= X to not give the wrong impression.

Comment thread cmd/frontend/graphqlbackend/schema.graphql
Comment thread cmd/frontend/graphqlbackend/schema.graphql Outdated
@taras-yemets taras-yemets changed the title Add Cody context filters to the site config and expose them via GraphQL DO NOT MERGE Add Cody context filters to the site config and expose them via GraphQL Apr 9, 2024
@taras-yemets taras-yemets changed the title DO NOT MERGE Add Cody context filters to the site config and expose them via GraphQL Add Cody context filters to the site config and expose them via GraphQL Apr 9, 2024
@keegancsmith keegancsmith self-requested a review April 9, 2024 14:47

@keegancsmith keegancsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I have high level design feedback with respect to the GraphQL. I would argue we shouldn't be modeling the shape of the config in graphql. I think we codyContextItems should return a string which is the marshalled JSON of the ignore rules. Two reasons:

  • A client should always want all fields. A subset of fields is an invalid. IE the whole config needs to live together.
  • Simplifies API / reduces scope of what we need to support w.r.t. API evolution.

However, I'm not a graphQL expert so I don't know if what I am saying is heresy.

Comment thread schema/site.schema.json
@taras-yemets

Copy link
Copy Markdown
Contributor Author

LGTM. I have high level design feedback with respect to the GraphQL. I would argue we shouldn't be modeling the shape of the config in graphql. I think we codyContextItems should return a string which is the marshalled JSON of the ignore rules. Two reasons:

  • A client should always want all fields. A subset of fields is an invalid. IE the whole config needs to live together.
  • Simplifies API / reduces scope of what we need to support w.r.t. API evolution.

However, I'm not a graphQL expert so I don't know if what I am saying is heresy.

Thanks for your review, @keegancsmith!
I think both exposing the Cody context filters via GraphQL in the same shape as the site config and as a stringified JSON could work for our current use case.

We discussed it with @valerybugakov (thanks for your input, Valery!) and he pointed out that, on one hand, clients will always need an entire filters config, thus they won't benefit from the granularity of the current approach. On the other hand, having types defined on the API level is more reliable than parsing opaque JSON structures on the client to extract the rules. With the opaque JSON structure, it's still possible to parse it incorrectly and use a subset of fields, this approach does not really prevent bugs when the subset of rules is used.

I also browsed the current GraphQL schema looking for similar cases. We return stringified JSON for the entire configurations (e.g., site config, settings, code host configs, etc.), but not for their subsets. It would probably be more consistent with the rest of the codebase to return explicit schema 🤔

I'm not a GraphQL expert either and I don't know the idiomatic way to handle such problems. I'm curious what other folks think of it.

@taras-yemets

Copy link
Copy Markdown
Contributor Author

For details see https://sourcegraph.com/docs/cody/capabilities/ignore-context
"""
codyContextFilters(
version: Int!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chwarwick, do you think version should be required? 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my thinking is that if the client is getting back a blob of json and the structure of that may change over time it should always be known what the version is. So if the client asks for v1 it should get v1 if it's possible to return.

By making it a required input we force the client to declare what version it can handle, and it gives us the opportunity to reject that tell the client it is out of date and can not be used.

@taras-yemets taras-yemets requested a review from chwarwick April 10, 2024 15:57
Comment thread cmd/frontend/graphqlbackend/schema.graphql Outdated
Comment thread cmd/frontend/graphqlbackend/schema.graphql Outdated
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend: Add repo-level Cody context include/exclude rules to the site config

8 participants