Strapi Crash Course (with React & GraphQL) #11 - Query Variables

preview_player
Показать описание
Hey gang, in this Strapi tutorial you'll learn how to use query variables in your GraphQL queries.

🐱‍💻 Access the course files on GitHub:

🐱‍👤 Get access to extra premium courses on Net Ninja Pro:

🐱‍💻Starter Project CSS (lesson 5):

🐱‍💻 Full React Course:

🐱‍💻 Social Links:
Рекомендации по теме
Комментарии
Автор

For those that had a problem with the query the correct one is
query GetReview($id: ID!) {

review(id: $id) {
data {
id
attributes{
title,
rating,
body
}
}
}
}

Dinos
Автор

Sir, please strapi js complete advanced tuotorial

kamalCode
Автор

Looks much easier with the REST method, any advantage using Graphql?

dannyelo
Автор

Great video!! Really enjoying this series, even with the updates!! Here is the code I adjusted to get it going:

import React from "react";
import { useParams } from "react-router-dom";

const GET_REVIEW = gql`
query GetReview($id: ID!) {
review(id: $id) {
data {
id
attributes {
title
rating
body
}
}
}
}
`;

export default function ReviewDetails() {
const { id } = useParams();
const { loading, error, data } = useQuery(GET_REVIEW, {
variables: { id: id },
});

if (loading) {
return <p>Loading...</p>;
} else if (error) {
return <p>Error! Something went wrong...</p>;
}

const review = data.review.data;

return (
<div>
<div className="review-card">
<div


</div>
</div>
);
}

tasanee
Автор

variables: {id: "undefined"}

how to fix it?

Status 200, but I get this error

paveldub
Автор

its sad how outdated is this list even though its only 1y old, i love this channel but this list is giving me a really hard time

anelabuawad
Автор

Hi Ninja, can we query slug instead of id? I tested several ways, but it doesn't work.

edgarwu
Автор

I'm asking my self if its so comllicated, why even learn it ? Have someone answer?

tomasmatusek
Автор

Very comlicated :
const REVIEW = gql`
query GetReview($id: ID!) {
review(id: $id) {
data {
id
attributes {
rating
title
body
}
}
}
}
`;

export default function ReviewDetails() {
const { id } = useParams();
const { loading, error, data } = useQuery(REVIEW, {
variables: { id },
});

if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;


return (
<div className="review-card">
<div

<small>console list</small>

{data.review.data.attributes.body.map((paragraph, index) => (
<p
))}
</div>
);
}

tomasmatusek
Автор

2023:
<div className="review-card">
<div


<small>console list</small>


</div>

null_excepton
visit shbcf.ru