-
Notifications
You must be signed in to change notification settings - Fork 57
Adding ability to process js, graphql, and other arbitrary file types (e.g. .gql) #51
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ export class ExtractGQL { | |
public queryTransformers: QueryTransformer[] = []; | ||
|
||
// The file extension to load queries from | ||
public extension: string; | ||
public extension: Array<string> = ['graphql']; | ||
|
||
// Whether to look for standalone .graphql files or template literals in JavaScript code | ||
public inJsCode: boolean = false; | ||
|
@@ -109,13 +109,13 @@ export class ExtractGQL { | |
inputFilePath, | ||
outputFilePath = 'extracted_queries.json', | ||
queryTransformers = [], | ||
extension = 'graphql', | ||
extension = '', | ||
inJsCode = false, | ||
}: ExtractGQLOptions) { | ||
this.inputFilePath = inputFilePath; | ||
this.outputFilePath = outputFilePath; | ||
this.queryTransformers = queryTransformers; | ||
this.extension = extension; | ||
this.extension = this.extension.concat(extension.split(',').map(e => e.trim())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this, we should just have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify this? If it's coming from the CLI how else do you propose I pass in an array of things? I could just let the variable be a string, and split it later? |
||
this.inJsCode = inJsCode; | ||
} | ||
|
||
|
@@ -193,8 +193,8 @@ export class ExtractGQL { | |
return Promise.resolve().then(() => { | ||
const extension = ExtractGQL.getFileExtension(inputFile); | ||
|
||
if (extension === this.extension) { | ||
if (this.inJsCode) { | ||
if (this.extension.indexOf(extension) > -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, should just be able to an array "contains" check rather than doing indexing on a string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume you mean |
||
if (this.inJsCode && extension === 'js') { | ||
// Read from a JS file | ||
return ExtractGQL.readFile(inputFile).then((result) => { | ||
const literalContents = findTaggedTemplateLiteralsInJS(result, this.literalTag); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import firstName from './fragment.gql'; | ||
import lastName from './fragment.graphql'; | ||
|
||
const query = gql` | ||
query { | ||
author { | ||
...firstName | ||
...lastName | ||
} | ||
} | ||
|
||
${firstName} | ||
${lastName} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fragment firstName on Author { | ||
firstName | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fragment lastName on Author { | ||
lastName | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import lastName from './fragment.graphql'; | ||
|
||
const frag = gql` | ||
fragment firstName on Author { | ||
firstName | ||
} | ||
`; | ||
|
||
const query = gql` | ||
query { | ||
author { | ||
...firstName | ||
...lastName | ||
} | ||
} | ||
|
||
${frag} | ||
${lastName} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fragment lastName on Author { | ||
lastName | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename this to be a plural thing rather than leave it "extension" since it is now an array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason I didn't change this is the
CLI
arg isextension
- and since renaming the arg would be a breaking change, elected to go with consistency.Obv easy / happy to do this, but wanted to explain my thinking.