Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gitlab): add proper client-side alias handling #6361

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions packages/client/components/GitLabScopingSearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ const GitLabScopingSearchResults = (props: Props) => {
>(
graphql`
fragment GitLabScopingSearchResults_query on Query
@argumentDefinitions(
projectsFirst: {type: "Int", defaultValue: 20}
issuesFirst: {type: "Int", defaultValue: 25}
projectsAfter: {type: "String"}
issuesAfter: {type: "String"}
search: {type: "String"}
projectIds: {type: "[ID!]", defaultValue: null}
)
@refetchable(queryName: "GitLabScopingSearchResultsPaginationQuery") {
@argumentDefinitions(
projectsFirst: {type: "Int", defaultValue: 20}
issuesFirst: {type: "Int", defaultValue: 25}
projectsAfter: {type: "String"}
issuesAfter: {type: "String"}
search: {type: "String"}
projectIds: {type: "[ID!]", defaultValue: null}
)
@refetchable(queryName: "GitLabScopingSearchResultsPaginationQuery") {
viewer {
...NewGitLabIssueInput_viewer
teamMember(teamId: $teamId) {
Expand Down Expand Up @@ -98,7 +98,6 @@ const GitLabScopingSearchResults = (props: Props) => {
edges {
node {
... on _xGitLabProject {
fullPath
issues(
includeSubepics: true
state: opened
Expand Down
15 changes: 10 additions & 5 deletions packages/server/graphql/public/rootSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {mergeSchemas} from '@graphql-tools/schema'
import {addResolversToSchema, mergeSchemas} from '@graphql-tools/schema'
import {GraphQLSchema} from 'graphql'
import nestGitHubEndpoint from 'nest-graphql-endpoint/lib/nestGitHubEndpoint'
import {IntegrationProviderGitLabOAuth2} from '../../postgres/queries/getIntegrationProvidersByIds'
Expand Down Expand Up @@ -66,11 +66,16 @@ const typeDefs = importAllStrings(require.context('./typeDefs', false, /.graphql

const withNestedSchema = mergeSchemas({
schemas: [withGitHubSchema, withGitLabSchema],
typeDefs,
// TODO apply this resolver to every type in the GitHub schema
// It is necessary any time client code uses an alias inside a wrapper
typeDefs
})

// IMPORTANT! mergeSchemas has a bug where resolvers will be overwritten by the default resolvers
// See https://github.com/ardatan/graphql-tools/issues/4367
const withNestedResolversSchema = addResolversToSchema({
schema: withNestedSchema,
resolvers: composeResolvers(resolvers, permissions)
})

const addRequestors = (schema: GraphQLSchema) => {
const finalSchema = schema as any
finalSchema.githubRequest = githubRequest
Expand All @@ -81,7 +86,7 @@ const addRequestors = (schema: GraphQLSchema) => {
}
}

const rootSchema = addRequestors(withNestedSchema)
const rootSchema = addRequestors(withNestedResolversSchema)

export type RootSchema = typeof rootSchema
export default rootSchema
2 changes: 1 addition & 1 deletion packages/server/graphql/public/types/_xGitLabProject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {_XGitLabProjectResolvers} from '../resolverTypes'

const _xGitLabProject: _XGitLabProjectResolvers = {
__isTypeOf: ({__typename}) => __typename === '_xGitLabProject',
__isTypeOf: ({id}) => id.startsWith('gid://'),
service: () => 'gitlab'
}

Expand Down
19 changes: 19 additions & 0 deletions packages/server/graphql/public/types/_xGitLabQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {GraphQLResolveInfo} from 'graphql'
import {_XGitLabQueryResolvers} from '../resolverTypes'

const resolveToFieldNameOrAlias = (
source: any,
_args: unknown,
_context: unknown,
info: GraphQLResolveInfo
) => {
// fieldNodes will always have 1+ node
const key = info.fieldNodes[0]!.alias?.value ?? info.fieldName
return source[key]
}

const _xGitLabQuery: _XGitLabQueryResolvers = {
projects: resolveToFieldNameOrAlias
}

export default _xGitLabQuery