System Information
- Strapi Version: 3.5.2
- Database: Mongodb
- Node Version: 14.12.0
- Yarn Version: 1.22.5
I’m working on a project and I discover I can use GraphQL in Strapi. I installed the plugin and then I try to use but I have few problems (I think that of syntax).
I have 2 Collections types: Lesson and Interests. The relation is Lesson should be 1 or many Interests.
Collection Typpes:
[Lesson]
title
lessonDate
interests ← relation with Interests collection type.
[Interests]
title
I want to get the all Lessons that the lessonDate is >= today + interests and the specific Interests (filter by ID, internal ID of created by Strapi).
I’m using this GraphlQL query
query {
lessons(
limit: 12,
start: 1,
sort: "lessonDate:asc",
where: {
lessonDate_lte: 1616691030933000, <--- TODAY IN TIMESTAMP*1000
interests: {
id_in: ["60427617425f0b627c0af8c5","604275a9425f0b627c0af8c1"]
}
}
) {
title,
id,
lessonDate,
interests {
id
}
}
}
And Strapi return:
{
"data": {
"lessons": [
{
"title": "Code 101: Python for beginners",
"id": "60427682425f0b627c0af8c7",
"lessonDate": "2021-03-12T12:00:00.000Z",
"interests": [
{
"id": "604275a9425f0b627c0af8c1"
}
]
},
{
"title": "test date",
"id": "6047ae3fa7c8595ae09f1cac",
"lessonDate": "2021-03-18T12:00:00.000Z",
"interests": [
{
"id": "604275f3425f0b627c0af8c2"
},
{
"id": "604275fd425f0b627c0af8c3"
},
{
"id": "60427617425f0b627c0af8c5"
}
]
},
{
"title": "Learn Strapi in 5 hours",
"id": "6051d364d9a66a4a085aba7d",
"lessonDate": "2021-03-18T12:00:00.000Z",
"interests": [
{
"id": "604275a9425f0b627c0af8c1"
}
]
},
{
"title": "Learn React",
"id": "605392475bd9330d8443f1ab",
"lessonDate": "2021-03-20T12:00:00.000Z",
"interests": [
{
"id": "604275a9425f0b627c0af8c1"
}
]
},
{
"title": "Creating memes",
"id": "60509f04b6afbb45b45a7ddb",
"lessonDate": "2021-03-22T12:00:00.000Z",
"interests": [
{
"id": "604275a9425f0b627c0af8c1"
},
{
"id": "60427603425f0b627c0af8c4"
}
]
},
{
"title": "HTML & CSS Basics",
"id": "60588a83aacc384f84bebff2",
"lessonDate": "2021-03-24T12:00:00.000Z",
"interests": [
{
"id": "604275a9425f0b627c0af8c1"
}
]
},
{
"title": "Morning Yoga",
"id": "60588ae3aacc384f84bebff3",
"lessonDate": "2021-03-29T11:00:00.000Z",
"interests": [
{
"id": "60427617425f0b627c0af8c5"
}
]
}
]
}
}
When the Interests is correctly filtered but the LessonDate not. If I change lessonDate_lte to lessonDate_gte Strapi return nothing
{
"data": {
"lessons": []
}
}
- I think that the problem is in the _lte/_gte syntax but I’m not sure. Can you help me?
- The LessonDate is a DateTime format in Strapi. Should I send the dateFormat in Timestamp or String (like “2021-03-12T12:00:00.000Z”)? If the answer is “timestamp”, I need to multiply *1000?
Thank you!!!