Skip to content

Document .graphql and .gql file loading with graphql.macro - #5481

Merged
amyrlam merged 7 commits into
react:masterfrom
petetnt:graphql-loader-docs
Apr 3, 2019
Merged

Document .graphql and .gql file loading with graphql.macro#5481
amyrlam merged 7 commits into
react:masterfrom
petetnt:graphql-loader-docs

Conversation

@petetnt

Copy link
Copy Markdown
Contributor

This PR follows up #3909 and #5076 by adding documentation for the .graphql loading features through babel-plugin-macros.

Signed-off-by: petetnt pete.a.nykanen@gmail.com

@petetnt

Copy link
Copy Markdown
ContributorAuthor

This should probably target the docs too https://github.com/facebook/create-react-app/blob/master/docusaurus/docs/

Signed-off-by: petetnt <pete.a.nykanen@gmail.com>
@petetnt

Copy link
Copy Markdown
ContributorAuthor

Aaaand now it targets the docusaurus docs 🦎

sidebar_label: Loading .graphql Files
---

You can load `.gql` and `.graphql` files by using [`babel-plugin-macros`](https://github.com/kentcdodds/babel-plugin-macros) included with Create React App.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's skip the part talking about macros and just combine these two sentences.

Comment threaddocusaurus/docs/loading-graphql-files.md Outdated
Comment threaddocusaurus/docs/loading-graphql-files.md Outdated
@petetnt

Copy link
Copy Markdown
ContributorAuthor

@Timer addressed comments, thanks!

@Timer

Copy link
Copy Markdown
Contributor

Shouldn't this come right after Relay docs?

@petetnt

petetnt commented Oct 24, 2018

Copy link
Copy Markdown
ContributorAuthor

Adding loading other types of assets (images, svgs, styles...) are on that section and AFAIK the graphql-tag loading isn't applicable to Relay so it might be a confusing. Then again they are both graphql related so it might make sense to put it there too anyway (that's where I put it when I opened this PR).

Anyway is fine with me, you can take the pick 😄

@TimerTimer added this to the 2.1 milestone Oct 24, 2018
Alternatively you may use `yarn`:

```sh
yarn add graphql-tag.macro

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you meant graphql.macro rather than graphql-tag.macro here

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks a ton @AndresRodH ! You are totally right, graphql.macro offers both the gql and the loader while graphql-tag only has the tag.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You missed this one! 😆yarn add graphql.macro

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Hahaa 🤦‍♂️ maybe it's fixed now. I blame the GitHub editor and doing changes on the go 😂

@petetnt

Copy link
Copy Markdown
ContributorAuthor

Thanks @AndresRodH for reviewing!

@audiolion

Copy link
Copy Markdown

Just going to throw this out there, graphql.macro currently doesn't support absolute paths, if you have a monorepo setup where your .gql files are stored in another package like @app/graphql and yarn workspaces symlinks it into the CRA app's node_modules, graphql.macro won't find it.

I made a PR which adds support for this, but, it looks like babel-plugin-macros doesn't apply to imports from node_modules. I ultimately had to run @babel/cli with a proper .babelrc setup and import compiled files to get graphql support to work in 2.0 after graphql and monorepo support was removed.

I am also somewhat concerned because it does not look like the repository is being actively maintained, I made a fork with absolute path and node modules path support at @kimmel/graphql.macro to use for now with the hope that the maintainer will become active.

@TimerTimer modified the milestones: 2.1, 2.1.xOct 28, 2018
Comment threaddocusaurus/docs/loading-graphql-files.md Outdated
Comment threaddocusaurus/docs/loading-graphql-files.md Outdated
donovantcand others added 2 commits February 14, 2019 16:40
Co-Authored-By: petetnt <pete.a.nykanen@gmail.com>
Co-Authored-By: petetnt <pete.a.nykanen@gmail.com>
@petetnt

Copy link
Copy Markdown
ContributorAuthor

Good catch @donovantc, fixed!

@petetnt

Copy link
Copy Markdown
ContributorAuthor

It seems that @audiolion's comment has been addressed in graphql.macro so this can probably be safely merged.

@iansuiansu closed this Feb 16, 2019
@iansuiansu reopened this Feb 16, 2019
@iansu

Copy link
Copy Markdown
Contributor

The deploy preview seems to be broken. Can you try rebasing with master to see if that fixes it?

@amyrlamamyrlam changed the title Document .graphql and .gql file loading with graphql-tag.macroDocument .graphql and .gql file loading with graphql.macroApr 3, 2019
@amyrlam
amyrlam merged commit d42f888 into react:masterApr 3, 2019
@locklockBot locked and limited conversation to collaborators Apr 8, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@petetnt@Timer@audiolion@iansu@donovantc@AndresRodH@amyrlam@facebook-github-bot