Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Adding ability to process js, graphql, and other arbitrary file types (e.g. .gql) #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mergebandit
Copy link

extension property / argument now supports multiple file types.

This allows users to execute persistgraphql in environments that utilize the gql tagged template literal, .graphql files, .gql files, and any arbitrary extension that consumers have defined for graphql files.

Specifically, the persistgraphql-webpack-plugin defines a loader for .graphql|.gql files, which was my original aim to support.

Fixes #50

@apollo-cla
Copy link

@mergebandit: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@@ -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'];
Copy link
Contributor

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

Copy link
Author

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 is extension - 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.

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()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, we should just have a this.extensions that we can pass in.

Copy link
Author

Choose a reason for hiding this comment

The 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?

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean array.includes(val) - the reason I didn't do this is the tsconfig.json is set for es6, and array.includes(val) is part of the es7 lib. Do you want me to include that?

@Poincare
Copy link
Contributor

@mergebandit Thanks so much for the PR! I mentioned a couple of changes above that should be pretty easy to implement. I think the concept is fine otherwise.

@mergebandit
Copy link
Author

@Poincare - left some responses above.

@Poincare
Copy link
Contributor

@mergebandit Yup saw those - will respond to each in about 1-2 days.

@mergebandit
Copy link
Author

Bump.

@mergebandit
Copy link
Author

Also - I'll need to bump the minor version in my next commit (reminder to myself)

@mergebandit
Copy link
Author

@Poincare I (and others on my team) would be more than happy to assist in ongoing maintenance and feature development for this plugin.

@mergebandit
Copy link
Author

Is this ever going to be addressed or should I just maintain a fork moving forward?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants