BigCommerce Stencil - GraphQL query using front matter not returning anything - bigcommerce

I'm not sure if it's a bug, but I'm not able to make GraphQL work in the Cornerstone template. I'm expecting an error or something getting returned at least, but nothing is being rendered at all from gql.
I am on the pages/product.html template, and I even tried this example from the docs:
---
product:
videos:
limit: {{theme_settings.productpage_videos_count}}
reviews:
limit: {{theme_settings.productpage_reviews_count}}
related_products:
limit: {{theme_settings.productpage_related_products_count}}
similar_by_views:
limit: {{theme_settings.productpage_similar_by_views_count}}
gql: "query productById($productId: Int!) {
site {
product(entityId: $productId) {
variants(first: 25) {
edges {
node {
sku
defaultImage {
url(width: 1000)
}
}
}
}
}
}
}
"
My goal is to have access to the paths/URL on each of the product's category because product.category is just an array of category names. Here's the query I am able to make work on the GraphQL playground (86 to be replaced by $productId in the front matter GraphQL query, I think?):
query getProductCategories {
site {
product(entityId: 86) {
categories {
edges {
node {
name
path
}
}
}
}
}
}
If there's no way around this, maybe I'll just try to do the fetching in the client side.

This now works correctly, as of 20-Sep-2021.
There was a bug, tracked as an issue here: https://github.com/bigcommerce/stencil-cli/issues/732 which has been resolved and closed.

Related

Http Headers vue-apollo

👩‍💻,
I have see many articles of how to use headers in apollo with context options but I don't know how to make it work in vue-apollo , is already other isssue in github about these (https://github.com/vuejs/vue-apollo/issues/713) config the vue-apollo.js, but I want to use headers to individuals querys, ¿Is these possible?.
My Query with vue-apollo:
apollo:{
getPipedrivePersons: {
query: gql`query{
getPipedrivePersons(
term:"email"
){
id
name
detail{
firstName
lastName
}
email{
value
}
phone{
value
}
}
}
`,
pollInterval: 950,
},
}
solved by using context:
context: {
headers: { foo: this.fooHeader }
}

GraphQL [Apollo-Android]: two `.watcher().enqueueAndWatch` creating infinite refresh loop

I'm requesting a list of 'posts' from my server using enqueueAndWatch and it is causing an infinite refresh loop.
The two queries are below:
query GetOrganizationPosts {
user {
organization {
posts {
...post
}
}
}
}
query GetUserPosts {
user {
posts {
...post
}
}
}
fragment post on Post {
id
title
messsage
}
The view model is initialized and the infinite loop occurs when I call refreshPosts() from the posts fragment:
init {
viewModelScope.launch {
networkClient.apolloClient.
query(GetOrganizationPostsQuery())
.watcher().enqueueAndWatch(callback)
networkClient.apolloClient
.query(GetUserPostsQuery())
.watcher().enqueueAndWatch(callback2)
}
}
fun refreshPosts() {
networkClient.apolloClient
.query(GetOrganizationPostsQuery())
.enqueue(null)
networkClient.apolloClient
.query(GetUserPostsQuery())
.enqueue(null)
}
Thanks in advance!
Workaround as described in Apollo-Android pull request: https://github.com/apollographql/apollo-android/issues/2226
Add .responseFetcher(ApolloResponseFetchers.CACHE_ONLY) to any enqueueAndWatch calls. This makes sure watchers don't perform network requests when the cache is updated.

How to fetch all repositories with specific topic, using GitHub GraphQL API?

I am trying to fetch all my repositories that contain topic "portfolio" using Github GraphQL API.
For now, I found only how to fetch all repos on github with a specific topic, like so :
{
search(type: REPOSITORY, query: "topic: portfolio", last: 50) {
repos: edges {
repo: node {
... on Repository {
url
}
}
}
}
}
And I know how to fetch all repos for a specific user, like so:
{
user(login: "VitFL") {
repositories(last: 50) {
repos: nodes {
url
}
}
}
}
But I have no idea how to combine those queries, so I could receive all repos with topic "portfolio" for a specific user.
Does anyone know how to achieve this result?
Using search(), a user argument can be added to the query value.
Also, the whitespace after the colon should be removed, i.e. topic: portfolio -> topic:portfolio. You will notice far more results with this change.
{
search(type: REPOSITORY, query: "user:VitFL topic:portfolio", last: 50) {
repos: edges {
repo: node {
... on Repository {
url
}
}
}
}
}

Read query from apollo cache with a query that doesn't exist yet, but has all info stored in the cache already

I have a graphql endpoint where this query can be entered:
fragment ChildParts {
id
__typename
}
fragment ParentParts {
__typename
id
children {
edges{
node {
...ChildParts
}
}
}
query {
parents {
edges
nodes {
...ParentParts
}
}
}
}
When executed, it returns something like this:
"data": {
"edges": [
"node": {
"id": "<some id for parent>",
"__typename": "ParentNode",
"children": {
"edges": [
node: {
"id": "<some id for child>",
"__typename": "ChildNode"
},
...
]
}
},
...
]
}
Now, with apollo client, after a mutation, I can read this query from the cache, and update / add / delete any ParentNode, and also any ChildNode, but I have to go over the structure returned by this query.
Now, I'm looking for a possibility to get a list of ChildNodes out of the cache (which has those already, as the cache is created as a flat list), to make the update of nested data a bit easier. Is there a possibility of reading a query out of the cache, without having read the same query from the server before?
You can use the client's readFragment method to retrieve any one individual item from the cache. This just requires the id and a fragment string.
const todo = client.readFragment({
id,
fragment: gql`
fragment fooFragment on Foo {
id
bar
qax
}
`,
})
Note that id here is the cache key returned by the dataIdFromObject function -- if you haven't specified a custom function, then (provided the __typename and id or _id fields are present) the default implementation is just:
${result.__typename}:${result.id || result._id}
If you provided your own dataIdFromObject function, you'll need to provide whatever id is returned by that function.
As #Herku pointed out, depending on the use case, it's also possible to use cache redirects to utilize data cached for one query when resolving another one. This is configured as part of setting up your InMemoryCache:
const cache = new InMemoryCache({
cacheRedirects: {
Query: {
book: (_, args, { getCacheKey }) =>
getCacheKey({ __typename: 'Book', id: args.id })
},
},
})
Unfortunately, as of writing this answer, I don't believe there's any method to delete a cached item by id. There's on going discussion here around that point (original issue here).

Error while using Paginated Lucene Search in cloudant

I'm currently having an issue in lucene cloudant implementation with pagination.
{"error":"scala.Symbol cannot be cast to org.apache.lucene.util.BytesRef","reason":null}
The URL that I am trying to access :
/_design/contact/search/name?q=name%3Asa%2A+OR+default%3Asa%2A&limit=10&bookmark=g1AAAAEPeJzLYWBgYMlgTmGQTUlKzi9KdUhJMtMrzsnMS9dLzskvTUnMK9HLSy3JASpjSmRIsv__38WmJPCwJJXmpOTGJeFqtscl-4kByCZVI9hQDyaAaa4DMhjAZIMDUAKaMZ-VEMyiXUFxJADEEPQXOKTlQUASZpV2Q&stale=ok&sort="name<string>"
What I found :
If I remove the bookmark ( means 1st page ) it works fine.
Or, If I remove the sort, it works fine.
below is the index that I created for this view :
"indexes": {
"name": {
"index": "function (doc)
{
if (doc.Type == 'contact')
{
index("default", doc._id);
index("name",doc.Name,{"store": "yes"});
if(doc.Profile) {index("profile", doc.Profile, {"store": "no"});}
if (doc.Aliases)
{
if (Array.isArray(doc.Aliases))
{
doc.Aliases.forEach(function (alias){
index("alias", alias, {"store":"yes"})
})
}
else
{
index("alias", doc.Alias_Name, {"store":"yes"})
}
}
}
}"
}
}
We have deployed a fix for this issue and you should no longer be experiencing this problem. Please confirm that that is the case. Thanks!