MCPcopy Index your code
hub / github.com/simstudioai/sim / buildIssuesQuery

Function buildIssuesQuery

apps/sim/connectors/linear/linear.ts:138–201  ·  view source on GitHub ↗

* Dynamically builds a GraphQL issues query with only the filter clauses * that have values, preventing null comparators from being sent to Linear.

(
  sourceConfig: Record<string, unknown>,
  teamIds: string[],
  projectIds: string[]
)

Source from the content-addressed store, hash-verified

136 * that have values, preventing null comparators from being sent to Linear.
137 */
138function buildIssuesQuery(
139 sourceConfig: Record<string, unknown>,
140 teamIds: string[],
141 projectIds: string[]
142): {
143 query: string
144 variables: Record<string, unknown>
145} {
146 const stateFilter = (sourceConfig.stateFilter as string) || ''
147
148 const varDefs: string[] = ['$first: Int!', '$after: String']
149 const filterClauses: string[] = []
150 const variables: Record<string, unknown> = {}
151
152 if (teamIds.length === 1) {
153 varDefs.push('$teamId: ID!')
154 filterClauses.push('team: { id: { eq: $teamId } }')
155 variables.teamId = teamIds[0]
156 } else if (teamIds.length > 1) {
157 varDefs.push('$teamIds: [ID!]!')
158 filterClauses.push('team: { id: { in: $teamIds } }')
159 variables.teamIds = teamIds
160 }
161
162 if (projectIds.length === 1) {
163 varDefs.push('$projectId: ID!')
164 filterClauses.push('project: { id: { eq: $projectId } }')
165 variables.projectId = projectIds[0]
166 } else if (projectIds.length > 1) {
167 varDefs.push('$projectIds: [ID!]!')
168 filterClauses.push('project: { id: { in: $projectIds } }')
169 variables.projectIds = projectIds
170 }
171
172 if (stateFilter) {
173 const states = stateFilter
174 .split(',')
175 .map((s) => s.trim())
176 .filter(Boolean)
177 if (states.length > 0) {
178 varDefs.push('$stateFilter: [String!]!')
179 filterClauses.push('state: { name: { in: $stateFilter } }')
180 variables.stateFilter = states
181 }
182 }
183
184 const filterArg = filterClauses.length > 0 ? `, filter: { ${filterClauses.join(', ')} }` : ''
185
186 const query = `
187 query ListIssues(${varDefs.join(', ')}) {
188 issues(first: $first, after: $after${filterArg}) {
189 nodes {
190 ${ISSUE_FIELDS}
191 }
192 pageInfo {
193 hasNextPage
194 endCursor
195 }

Callers 1

linear.tsFile · 0.85

Calls 2

joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected