Skip to content
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

Adding headers to graphql query #178

Closed
lopandpe opened this issue Jun 9, 2023 · 3 comments
Closed

Adding headers to graphql query #178

lopandpe opened this issue Jun 9, 2023 · 3 comments

Comments

@lopandpe
Copy link

lopandpe commented Jun 9, 2023

The developers of the API we are targeting have implemented a requirement that products in a language other than the default (Spanish) are retrieved by sending a header. In a regular GraphQL query, we would include those headers in the request, but I'm not sure how to pass them to Algolia.

I have seen that there is, if I'm not mistaken, the option queryVariables, but not queryHeaders, right?

I've tried some options without success:

  {
    query: pageQuery,
    transformer: ({ data }) => data.api.products.data.map(pageToAlgoliaRecord),
    indexName,
    settings: {
      attributesToSnippet: [`description:20`],
      attributesForFaceting: [`searchable(type.name)`],
      searchableAttributes: [
        `name`, 
        `description`,
      ],
    },
    queryHeaders: { //option 1
      'Content-Language': 'en',
    },
    headers: { //option 2
      'Content-Language': 'en',
    },
  },

I would appreciate any hints, please!

@Haroenv
Copy link
Contributor

Haroenv commented Jun 12, 2023

The arguments are passed like this to the grapql function:

const result = await graphql(query, queryVariables);

If you'd call graphql, which arguments would you use? happy to add those

@lopandpe
Copy link
Author

I finally convinced the api developers to be able to send lang as a variable.

What I was wondering was how to add http headers to graphql, like language or maybe a bearer token.

Anyway, thanks for your help :-)

@Haroenv
Copy link
Contributor

Haroenv commented Jun 14, 2023

I'll close this issue for now then, but if anyone else needs to pass any parameters to the graphql function, I'm happy to add those.

@Haroenv Haroenv closed this as completed Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants