Missing analytics attribute on result - graphql

apollo: {
analytics: gql `
query getAnalyticsViews {
viewer {
zones(filter: { zoneTag: "tag" }) {
httpRequestsAdaptiveGroups(
filter: {
clientRequestHTTPHost: "domain.co.uk"
date_geq: "2023-01-01"
date_leq: "2023-01-24"
requestSource: "eyeball"
}
limit: 1
) {
sum {
visits
edgeResponseBytes
}
}
}
}
}
`
}
The above is my Apollo GraphQL query, which works fine in Altair and returns the below:
{
"data": {
"viewer": {
"zones": [
{
"httpRequestsAdaptiveGroups": [
{
"sum": {
"edgeResponseBytes": 4542764000,
"visits": 1200
}
}
]
}
]
}
},
"errors": null
}
This is my views component where I am trying to access the sum, visits:
<div v-if="analytics">
{{ analytics.viewer.zones[0].httpRequestsAdaptiveGroups[0].sum.visits }}
</div>
In console I can see the data I need under said structure which I copied:
analytics.viewer.zones[0].httpRequestsAdaptiveGroups[0].sum.visits
but I am getting error as shown below:
Missing analytics attribute on result
No idea why this isn't working, I've tried conditionally loading it, but hasn't helped, as I said above the data sums, visits is in console(see image), but not in the component :(

Fixed:
The issue I was facing was:
analytics: gql `
query getAnalyticsViews {
viewer {
Needed to be:
viewer: gql `
query getAnalyticsViews {
viewer {

Related

GraphQL parameters for an exists filter in API Platform

I have setup an exists filter for an entity:
#[ApiFilter(ExistsFilter::class, properties: ['firstName', 'lastName'])]
I can then run the query just fine:
query accounts {
accounts(exists: {firstName: true}) {
edges {
node {
id
}
}
}
}
But I would like to parameterize the exists filter. The closest I have got is this:
Query
query getAccounts($exists: [AccountFilter_exists]) {
accounts(exists: $exists) {
edges {
node {
id
}
}
}
}
Parameters
{
"exists": {"firstName": true}
}
But I get this error message:
{
"errors": [
{
"message": "Variable \"$exists\" got invalid value {\"firstName\":true}; Expected type AccountFilter_exists to be an object at value.firstName.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 1,
"column": 19
}
]
}
]
}
Does anyone know where I am going wrong?
Thanks for your help.
You actually need to provide the exists filters in this format:
{
"exists": [{"firstName": true}]
}
https://api-platform.com/docs/v2.7/core/graphql/#syntax-for-filters-with-a-list-of-key--value-arguments
Hope this helps.

shorten the graphql field value

I am trying to fetch image path in an alias field using graphql, I am able to get output like this:
Output:
{
"data": {
"leaders": [
{
"partyImg": {
"image": {
"url": "/uploads/17a5f020cc974679ac52e56a22b74dd6.png"
}
}
},
{
"partyImg": {
"image": {
"url": "/uploads/70bd673d41654058847e39c14cda5fef.png"
}
}
},
{
"partyImg": {
"image": {
"url": "/uploads/c54a0ace0bb34da3985c67945b1d0bf0.png"
}
}
}
]
}
}
When I used the following graphql code:
Input:
query Leaders{
leaders{
partyImg: party{image: Image{ url }},
}
}
The output I am trying to get is:
Expected output:
{
"data": {
"leaders": [
{
"partyImg": "/uploads/17a5f020cc974679ac52e56a22b74dd6.png"
},
{
"partyImg": "/uploads/70bd673d41654058847e39c14cda5fef.png"
},
{
"partyImg": "/uploads/c54a0ace0bb34da3985c67945b1d0bf0.png"
}
]
}
}
Please help me to prepare the graphql input which could generate the expected output.
It appears the graphql schema prevents you from getting the data in the format that you want. Based on your input query, I expect the schema looks something like this:
query {
leaders: [Leader]
}
type Leader {
party: Party
}
type Party {
Image: Image
}
type Image {
url: String
}
To get the data in the format that you want, you would need a schema that looks more like:
query {
leaders: [Leader]
}
type Leader {
party: Party,
imageUrl: String
}
Then you could do:
query Leaders {
leaders {
partyImg: imageUrl
}
}
I assume you don't control the schema, so you would have to do post processing. If you are using javascript, the following could work for the above output as a simple mapping exercise.
(function() {
var output = {
"data": {
"leaders": [{
"partyImg": {
"image": {
"url": "/uploads/17a5f020cc974679ac52e56a22b74dd6.png"
}
}
},
{
"partyImg": {
"image": {
"url": "/uploads/70bd673d41654058847e39c14cda5fef.png"
}
}
},
{
"partyImg": {
"image": {
"url": "/uploads/c54a0ace0bb34da3985c67945b1d0bf0.png"
}
}
}
]
}
};
var transformed = {
data: {
leaders: output.data.leaders.map(function flattenUrl(item) {
return {
partyImg: item.partyImg.image.url
};
})
}
}
document.getElementById('transformedOutput').innerHTML = JSON.stringify(transformed);
}());
<div id="transformedOutput"></div>
If you are the author of this graphql schema, you can structure it in whatever way makes the most sense to your applications and/or consumers.

GraphiQL 404 page not found

Based on this Shopify documentation, I'm trying to execute this GraphQL query:
query getDiscount($code: DiscountCodeSortKeys) {
priceRules(first: 1) {
edges {
node {
discountCodes(first: 1, sortKey: $code) {
edges {
node {
code
id
}
}
}
}
}
}
}
In GraphiQL in my Shopify admin page I get this output:
{
"data": {
"priceRules": {
"edges": [
{
"node": {
"discountCodes": {
"edges": [
{
"node": {
"code": "discount_code_1",
"id": "gid://shopify/PriceRuleDiscountCode/1888888"
}
}
]
}
}
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 6,
"actualQueryCost": 6,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 994,
"restoreRate": 50
}
}
}
}
However, when I execute the same query in GraphiQL IDE after editing the HTTP headers and putting the GraphQL endpoint (https://my_domain.com/api/graphql), I get a html code with the title of 404 page not found as you can see in the picture below:
The problem was in the selected method "GET", it worked when I selected the "POST" method.

prismic graphql querying single user

I'm trying to figure out how to query a single user from graphql schema by id. I'm using the graphiql tool and I'm able to get all Users.
{
allPrismicUsers {
edges {
node {
id
data {
name
}
}
}
}
}
Outputs :
{
"data": {
"allPrismicUsers”: {
"edges": [
{
"node": {
"id": "Prismic__User__WzKFwywAABmiZk_4",
"data": {
"name": “John Doe”
}
}
},
{
"node": {
"id": "Prismic__User__WzKDZywAABmiZkYp",
"data": {
"name": “Jane Doe“
}
}
},
{
"node": {
"id": "Prismic__User__WzKGDiwAAJSiZlFL",
"data": {
"name": “Cat Doe”
}
}
}
]
}
}
}
I also have prismicUser() on the schema
query {
prismicUser {
id
data {
name
}
}
}
Output:
{
"data": {
"prismicUser": {
"id": "Prismic__User__WzKGDiwAAJSiZlFL",
"data": {
"name": "Cat Doe"
}
}
}
}
I'm trying to query a user based on a specific id but not sure if I'm querying the wrong way.
I tried this.
query {
prismicLocation(id: "Prismic__User__WzKDZywAABmiZkYp") {
data {
name
}
}
}
I get an error
{ "errors": [
{
"message": "Argument \"id\" has invalid value \"Prismic__User__WzKDZywAABmiZkYp\".\nExpected
\"prismicUserIdQueryString_2\", found not an object.",
"users": [
{
"line": 25,
"column": 23
}
]
} ] }
How can I call a specific user based on their id ?
According to the Gatsby GraphQL reference, Gatsby allows you to filter results by any field in GraphQL (using operators such as eq, ne, etc.)
The gatsby-source-prismic plugin provides a field called prismicId (i.e. W1syKSIAAAzdN1Jg).
Here is an example query:
{
prismicUser(prismicId:{eq:"WzKDZywAABmiZkYp"}) {
data {
name
}
}
}
But you can also query by id:
prismicUser(id:{eq:"Prismic__User__WzKDZywAABmiZkYp"})

RestHeart passing multiple parametrs in aggregation

Basically I am trying to use REST hreat to create two variables issuerId and sectionName. I am trying to get data from the URI mentioned below
http://ftc-wbpyrdb201:8080/statdata/InsStatData/_aggrs/getDataByIssuerAndSectionName?avars={"issuerId":19038},{"sectionName":"ASSETS"}
My aggregation definition is a below
{"$push" : {
"aggrs":
{
"type": "pipeline",
"uri": "getDataByIssuerAndSectionName",
"stages": [
{
"_$match": {
"_$and": [
{"issuerId": {"_$var": "issuerId" }},
{
"sectionName": {"_$var": "sectionName"}
}
]
}
},
{
"_$unwind": "$sections"
},
{
"_$unwind": "$sections.data"
},
{
"_$unwind": "$sections.data.values"
},
{
"_$match": {
"_$and": [
{"issuerId": {"_$var": "issuerId" }},
{
"sectionName": {"_$var": "sectionName"}
}
]
}
}
]
}
}
}
I am sure I am doing something wring in either defining the aggregation or while requesting the URI. There is not enough in the documentation. Please help me with this request.

Resources