Skip to content

Conversation

@fregante
Copy link
Member

@fregante fregante commented May 20, 2023

This PR

This is harder than anticipated:

  • you can't include variable data in the JSON and not use them (i.e. no default user/repo)
  • you can't just use variables; each query must ALSO declare them…
- query {
+ query ($owner: String!, $name: String!) {
    repository(owner: $owner, name: $name) {

Test

Extensions suggested:

@fregante fregante added the meta Related to Refined GitHub itself label May 20, 2023
@fregante fregante marked this pull request as draft May 20, 2023 18:44
@yakov116
Copy link
Member

JMHO, on any non simple query I think this lowers readability

@fregante
Copy link
Member Author

It’s definitely more verbose but there’s no alternative if we want to extract the queries:

Once extracted we’ll have syntax highlighting and potentially some validation, as well as proper types for v4 calls. I think it’s worth it, even if the query ends up being in a different file.

@fregante fregante changed the title Use variables in GraphQL Meta: Use variables in GraphQL May 21, 2023
@fregante fregante marked this pull request as ready for review May 21, 2023 12:44
Copy link
Member Author

@fregante fregante left a comment

Choose a reason for hiding this comment

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

Everything here was tested. Some features were even restored, some tickets were created.

In a future PR:

  • Extract to .gql files
  • Update every query (I ignored the simple ones without additional variables, although they're still affected by this change)

Copy link
Member Author

@fregante fregante left a comment

Choose a reason for hiding this comment

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

You can see what the usage of .gql files will look like in list-prs-for-file

Missing:

  • TypeScript integration that will help us use the results in the file
  • GraphQL autocomplete in the IDE thanks to the schema
  • Typed variables that make TypeScript complain if one is missing or unused
  • Prettier/formatter for GQL support (we have a .prettierignore file)

field: UPDATED_AT,
direction: DESC
}
) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Demo extracted GQL file

}
`);
debugger;
const {repository} = await api.v4(listPrsForFileQuery, {
Copy link
Member Author

Choose a reason for hiding this comment

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

Demo feature with extracted query

Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Can we put this in a new pr?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind just saw your post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

Fix our GraphQL usage (use native variables)

2 participants