Hello dear support team,
slowly getting the hang of the powerful prismic graphql interface. I am having a little issue querying by date from apollo in reactjs. works fine in the graphql browser.
This didn't work: Latest Apollo Client sends Date objects as {} and now requires .toISOString() · Issue #4335 · apollographql/apollo-client · GitHub
my apollo query:
const { loading, error, data } = useQuery(
getBroadcastsInRangeQuery,
{
variables:
{
endAfter: new Date(),
beginBefore: new Date(),
},
pollInterval: 60 * 1000
});
Error Message:
{
"data": null,
"errors": [
{
"message": "Variable '$endAfter' expected value of type 'DateTime!' but got: \"2023-04-04T14:30:48.695Z\". Reason: Date value expected (line 1, column 28):\nquery GetBroadcastsInRange($endAfter: DateTime!, $beginBefore: DateTime){allBroadcastss( sortBy: begin_ASC where:{end_after: $endAfter, begin_before: $beginBefore}){pageInfo{hasNextPage endCursor __typename}totalCount edges{node{...broadcast __typename}__typename}__typename}}fragment broadcast on Broadcasts{_meta{uid id firstPublicationDate __typename}title hostedby{... on Shows{title __typename}__typename}description begin end length keyword image audio{... on _FileLink{name url size _linkType __typename}__typename}tags{...broadcastTags __typename}__typename}fragment broadcastTags on BroadcastsTags{tag{_linkType __typename}__typename}\n ^",
"locations": [
{
"line": 1,
"column": 28
}
]
},
{
"message": "Variable '$beginBefore' expected value of type 'DateTime' but got: \"2023-04-04T14:30:48.695Z\". Reason: Date value expected (line 1, column 50):\nquery GetBroadcastsInRange($endAfter: DateTime!, $beginBefore: DateTime){allBroadcastss( sortBy: begin_ASC where:{end_after: $endAfter, begin_before: $beginBefore}){pageInfo{hasNextPage endCursor __typename}totalCount edges{node{...broadcast __typename}__typename}__typename}}fragment broadcast on Broadcasts{_meta{uid id firstPublicationDate __typename}title hostedby{... on Shows{title __typename}__typename}description begin end length keyword image audio{... on _FileLink{name url size _linkType __typename}__typename}tags{...broadcastTags __typename}__typename}fragment broadcastTags on BroadcastsTags{tag{_linkType __typename}__typename}\n ^",
"locations": [
{
"line": 1,
"column": 50
}
]
}
]
}
Graphql Query
query GetCurrentBroadcast($endAfter:DateTime!, $beginBefore:DateTime) {
allBroadcastss(sortBy: begin_ASC, where: { end_after: $endAfter, begin_before: $beginBefore }) {
pageInfo {
hasNextPage
endCursor
}
totalCount
edges {
node {
...broadcast
}
}
}
}
fragment broadcast on Broadcasts {
_meta {
uid
id
firstPublicationDate
}
title
hostedby {
... on Shows {
title
}
}
description
begin
end
length
keyword
image
audio {
... on _FileLink {
name
url
size
_linkType
}
}
tags {
...broadcastTags
}
}
fragment broadcastTags on BroadcastsTags {
tag {
_linkType
}
}
Please forgive me using Broadcastss (with so many s) ... a misconception at the beginning, but too late to fix now, but too like traffic to migrate. I am waiting for the page to scale and fix this then. yes, messy, but works for the moment.