-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide better example using page queries #16
Comments
Hi @daniloraisi, I think you missed to include the error that you are referring to. |
@daaru00, {
"error": {
"errors": [
{
"message": "Unknown argument \"lang\" on field \"allCareer\" of type \"Query\".",
"stringified": "Unknown argument \"lang\" on field \"allCareer\" of type \"Query\".\n\nGraphQL request:2:21\n1 | query ($locale: String) {\n2 | career: allCareer(lang: $locale, sortBy: \"order\", order: ASC) {\n | ^\n3 | edges {"
}
]
}
} |
I solved my problem using another approach. |
@daniloraisi can you share how did you do it? I'm having the same error here query($locale: String, $page: Int) {
chapters: allChapter(filter: { lang: $locale }) {
// ... rest of code
}
} |
Well in case anyone sees this issue, I was unable to add the |
Hi all @daniloraisi your error concerns the server, the error say that you cannot use "lang" parameters because does not exist. Try to replicate the same in query in playground, the correct parameter should auto-complete. @rodrigomata your error is about the syntax, where you are passing In general I don't think there can be an error different from "the local parameter cannot be undefined / null", this plugin just add a property into the context (automatically passed as query parameters), doesn't do any other manipulation of the query. The same thing as doing: createPage({
path: 'my-page',
component: './src/templates/Page.vue',
context: {
locale: 'en'
}
}) So it can only be there or not, other errors are not attributable to this plugin but to an incorrect use of grqphql. Please try to replicate the exact same query, with parameters, in GraphQL's playground (http://localhost:8080/___explore), if it also raise an error maybe the problem is not the here. |
@daaru00 First, I appreciate the great job you did on this plugin. I'm using it because worth it! I've tried on GraphQL's Playground too. Same error. There's no "lang" param on any query. As I said on my previous comment => #16 Comment already solved using another approach. For better understand, what I said first is to provide a better example using page-query. On documentation we can find: <page-query>
query($locale:String) {
example {
_allDocuments(lang:$locale) {
edges {
node {
title
}
}
}
}
}
</page-query> But:
As you can see, I have no lang param on my query even on GraphQL's Playground Is it necessary to change something on gridsome.server.js too? I can use |
@rodrigomata Here what I did: First I created a separated page structure for each language: Each page have a Front matter with locale and type ---
...
locale: en-US
type: staff
--- Then I use module.exports = {
...
templates: {
Translations: (node) => node.path
},
plugins: [
{
use: 'gridsome-plugin-typescript'
},
{
use: '@gridsome/source-filesystem',
options: {
path: 'pages/**/*.md',
typeName: 'Translations'
}
},
{
use: 'gridsome-plugin-i18n',
options: {
locales: ['pt-BR', 'en-US'],
pathAliases: {
'pt-BR': 'br',
'en-US': 'us'
},
fallbackLanguage: 'pt-BR',
defaultLocale: 'pt-BR',
messages: {} // Loading messages from main.ts
}
}
]
}; In main.ts I load my messages: export default function (Vue: any, { router, appOptions, head }: any) {
appOptions.i18n.setLocaleMessage('pt-BR', require('./locales/pt-BR.json'));
appOptions.i18n.setLocaleMessage('en-US', require('./locales/en-US.json'));
...
} Now, when I want to use i just need to create a <page-query>
query($locale: String) {
staff: allTranslations(filter: { locale: { eq: $locale }, type: { eq: "staff" } }) {
edges {
node {
title
content
}
}
}
}
</page-query> I think if you change your code to this should work: query($locale: String, $page: Int) {
chapters: allChapter(filter: { lang: { eq: $locale } }) {
// ... rest of code
}
} |
Hey @daniloraisi thanks for sharing. @daaru00 keep the awesome work and thanks for the explanation. |
Hi all, can I consider this issue closed? have you solved your doubts? @daniloraisi can I link your solution into README as use case with |
Yes, you can close! @daaru00 For sure, you can use my solution as use case, it's working perfectly on my end. |
Describe the bug
Trying to use gridsome-plugin-i18n with page-query but I got an error
To Reproduce
After configure gridsome-plugin-i18n create any page using page-query applying lang filter as shown on README.
Expected behavior
Query execute without error
Environment (please complete the following information):
Plugin configuration
The text was updated successfully, but these errors were encountered: