Skip to content

Commit

Permalink
chore(gatsby): Convert query-runner to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
mottox2 committed Mar 20, 2020
1 parent 8dd2cc2 commit 219d82b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/gatsby/src/query/error-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { SourceLocation } from "graphql"

interface IErrorParser {
message: string
filePath: string | undefined
location:
filePath?: string | undefined
location?:
| {
start: SourceLocation
end?: SourceLocation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
// @flow
import fs from "fs-extra"
import report from "gatsby-cli/lib/reporter"

const fs = require(`fs-extra`)
const report = require(`gatsby-cli/lib/reporter`)
import path from "path"
import { store } from "../redux"
import { boundActionCreators } from "../redux/actions"
import pageDataUtil from "../utils/page-data"
import { getCodeFrame } from "./graphql-errors"
import errorParser from "./error-parser"

const path = require(`path`)
const { store } = require(`../redux`)
const { boundActionCreators } = require(`../redux/actions`)
const pageDataUtil = require(`../utils/page-data`)
const { getCodeFrame } = require(`./graphql-errors`)
const { default: errorParser } = require(`./error-parser`)
import { GraphQLRunner } from "./graphql-runner"
import { ExecutionResultDataDefault } from "graphql/execution/execute"
import { ExecutionResult } from "graphql"

const resultHashes = new Map()

type QueryJob = {
id: string,
hash?: string,
query: string,
componentPath: string,
context: Object,
isPage: Boolean,
interface IQueryJob {
id: string
hash?: string
query: string
componentPath: string
context: {
path: any
context: any
}
isPage: boolean
pluginCreatorId: string
}

// Run query
module.exports = async (graphqlRunner, queryJob: QueryJob) => {
export const queryRunner = async (
graphqlRunner: GraphQLRunner,
queryJob: IQueryJob
): Promise<ExecutionResult<ExecutionResultDataDefault>> => {
const { program } = store.getState()

const graphql = (query, context) => graphqlRunner.query(query, context)
const graphql = (
query: string,
context: any
): Promise<ExecutionResult<ExecutionResultDataDefault>> =>
graphqlRunner.query(query, context)

// Run query
let result
let result: ExecutionResult<ExecutionResultDataDefault>
// Nothing to do if the query doesn't exist.
if (!queryJob.query || queryJob.query === ``) {
result = {}
Expand Down Expand Up @@ -62,7 +75,7 @@ module.exports = async (graphqlRunner, queryJob: QueryJob) => {
e.locations && e.locations[0].column
),
filePath: queryJob.componentPath,
...(urlPath && { urlPath }),
...(urlPath ? { urlPath } : {}),
...queryContext,
plugin,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface IMatch {
id: string
context: {
sourceMessage: string
[key: string]: string
[key: string]: unknown
}
error?: Error | undefined
[key: string]: unknown
Expand Down

0 comments on commit 219d82b

Please sign in to comment.