Skip to content

Commit

Permalink
refactor(ui): use locally generated AST fetching utils
Browse files Browse the repository at this point in the history
Moves the handwritten AST wrapper types from influxdb-client-js back
into the UI. Long term I think we should improve the `swagger.yml` spec
for these types so that we can use their generated counterparts. This
will take some tedious labor and a review from the Flux team.

Part of #14482
  • Loading branch information
chnn committed Jul 30, 2019
1 parent 918ca3e commit f01f7b9
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 37 deletions.
30 changes: 0 additions & 30 deletions ui/src/shared/apis/ast.ts

This file was deleted.

15 changes: 9 additions & 6 deletions ui/src/shared/utils/insertPreambleInScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import {get} from 'lodash'

// APIs
import {getAST} from 'src/shared/apis/ast'
import {postQueryAst} from 'src/client'

// Types
import {ImportDeclaration, Statement} from 'src/types/ast'
import {Package, ImportDeclaration, Statement} from 'src/types/ast'

export const insertPreambleInScript = async (
script: string,
Expand All @@ -15,10 +15,13 @@ export const insertPreambleInScript = async (
return `${preamble}\n\n${script}`
}

// TODO: replace this with `import {parse} from '@influxdata/flux-parser'`
// when the flux team adds location.source data to the rust implementation
// https://github.com/influxdata/influxdb/issues/14467
const ast = await getAST(script)
const resp = await postQueryAst({data: {query: script}})

if (resp.status !== 200) {
throw new Error(resp.data.message)
}

const ast = resp.data.ast as Package

const imports: ImportDeclaration[] = get(ast, 'files.0.imports', [])
const body: Statement[] = get(ast, 'files.0.body', [])
Expand Down
Loading

0 comments on commit f01f7b9

Please sign in to comment.