Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Add query string to type definition (gatsby-config.js) in order to handle i18n #193

Merged
merged 6 commits into from
Apr 30, 2021

Conversation

8byr0
Copy link
Contributor

@8byr0 8byr0 commented Apr 26, 2021

@alexandrebodin there we go, I applied your idea that was indeed the best way to handle this problem.

I've updated README accordingly.

I've also added queryLimit param to this new behavior. It can now be overriden individually for each type.

@strapi-cla
Copy link

strapi-cla commented Apr 26, 2021

CLA assistant check
All committers have signed the CLA.

src/fetch.js Outdated
const params = { _limit: queryLimit, ...api?.qs };

// Retrieve qs params if defined (or empty string instead)
const qs = Object.keys(params)
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't necessary with axios you can pass the query string as an object into the params property of the options

example:

const requestOptions = {
  method: 'GET',
  url: apiBase,
  params{ _limit: 100, ...api?.qs },
  headers: {}
}

await axios(requestOptions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, better like this... Fixed in commit below

Copy link
Contributor

@remidej remidej left a comment

Choose a reason for hiding this comment

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

Hello! Thanks for submitting this PR so early after the i18n release.

I tested it locally and it's working fine. I just have one concern with it. It's about these examples in the readme:

// exemple fetching only english content
{
   name: `collection-name`,
   api: { qs: { _locale: 'en' } }
 },

It seems like when we provide an entityDefinition object, the pluralize module is disabled. So I'm afraid users might copy this config and get a 404, because the plugin will not pluralize the collection name to find the endpoint.

So I would recommend either:

  • Adding the endpoint property to the readme examples
  • Only disabling the pluralize module if the endpoint key is provided. Not just if there's an entityDefinition object

README.md Outdated
@@ -58,6 +69,23 @@ You can query Document nodes created from your Strapi API like the following:
}
```

You can query Document nodes in chosen language
> make sure to add `api.qs._locale` to your strapi conf in `gatsby-config.js` (see example above)
Copy link
Contributor

Choose a reason for hiding this comment

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

Strapi conf is its own thing, so I'd recommend typing "configuration" entirely

Also, I don't think this needs to be a quote (>), you can add this as text directly

And I would say "You can query Document nodes in a chosen language"

@8byr0
Copy link
Contributor Author

8byr0 commented Apr 28, 2021

@remidej you were right, I've been missing pluralization if no endpoint provided, this is fixed now. (So I've not updated the example in the README, will work just fine now).
README typos fixed too

@8byr0 8byr0 requested a review from remidej April 28, 2021 10:54
Copy link
Contributor

@remidej remidej left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, it's working well now

@juliensl
Copy link

Hi guys !

Thank you for your work :D

Do you have an idea for when it will be usable and published in npm ? :)

Thank you !

Copy link
Contributor

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

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

LGTM

@remidej remidej merged commit 5a09ffb into gatsby-uc:master Apr 30, 2021
@remidej remidej added this to the 1.0.0 milestone Apr 30, 2021
@remidej
Copy link
Contributor

remidej commented Apr 30, 2021

Thanks again @8byr0

@juliensl we'll publish this as part of a new alpha release on NPM early next week. We're just waiting for a couple more changes we'd like to add to that release

@juliensl
Copy link

So great ! Thank you @remidej and thank you too @8byr0 😃

@8byr0 8byr0 deleted the feature/handleQsParams branch April 30, 2021 22:32
@juliensl
Copy link

Hi everybody ! :)

Do you know when the feature will be available on npm ?
Or, do you know how can I add this commit in my plugin please ?

Thank you

@remidej
Copy link
Contributor

remidej commented May 11, 2021

Hello @juliensl

We just published an alpha release with this feature: https://www.npmjs.com/package/gatsby-source-strapi/v/1.0.0-alpha.2

Just know that there's a small mistake in the readme example that I'll fix tomorrow:

filter: { locale: “en” }
should be ⬇️
filter: { locale: { eq: “en” } }

Sign up for free to 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.

5 participants