Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityGarmin Cirqa im Test: Fitness-Tracker ohne Display(22.09.2026 um 10:30 Uhr)
Windows Tipps & SecuritySicher online bezahlen: 7 Methoden im Praxis-Check(22.09.2026 um 09:00 Uhr)
Sichere Programmierunghas_tokens: true is a boolean. 476 of 791 have no market behind them.(22.09.2026 um 10:00 Uhr)
Sichere ProgrammierungClaude Code Hooks – Safety Through Invariants(22.09.2026 um 10:04 Uhr)
Sichere ProgrammierungYour MCP Tool Just Returned a Secret. Did It Need To?(22.09.2026 um 10:05 Uhr)
Windows Tipps & SecurityGarmin Cirqa im Test: Fitness-Tracker ohne Display(22.09.2026 um 10:30 Uhr)
Windows Tipps & SecuritySicher online bezahlen: 7 Methoden im Praxis-Check(22.09.2026 um 09:00 Uhr)
Sichere Programmierunghas_tokens: true is a boolean. 476 of 791 have no market behind them.(22.09.2026 um 10:00 Uhr)
Sichere ProgrammierungClaude Code Hooks – Safety Through Invariants(22.09.2026 um 10:04 Uhr)
Sichere ProgrammierungYour MCP Tool Just Returned a Secret. Did It Need To?(22.09.2026 um 10:05 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Build a Simple ToDo App with React and GraphQL

Have you ever wondered how to build a full-stack app using GraphQL instead of REST? In this tutorial, we’ll walk through how to create a simple ToDo app using React and GraphQL with Apollo. 🎯 By the end, you’ll have a working app where you…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Have you ever wondered how to build a full-stack app using GraphQL instead of REST? In this tutorial, we’ll walk through how to create a simple ToDo app using React and GraphQL with Apollo.



🎯 By the end, you’ll have a working app where you can view, add, and toggle tasks — powered by a GraphQL API.



Step 1: Set Up the GraphQL Server (Backend)




mkdir graphql-server
cd graphql-server
npm init -y
npm install apollo-server graphql






Create index.js for the backend




const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`
type Todo {
id: ID!
title: String!
completed: Boolean!
}

type Query {
todos: [Todo]
}

type Mutation {
addTodo(title: String!): Todo
toggleTodo(id: ID!): Todo
}
`;

let todos = [
{ id: "1", title: "Learn GraphQL", completed: false },
{ id: "2", title: "Build a ToDo App", completed: false },
];

const resolvers = {
Query: {
todos: () => todos,
},
Mutation: {
addTodo: (_, { title }) => {
const newTodo = { id: Date.now().toString(), title, completed: false };
todos.push(newTodo);
return newTodo;
},
toggleTodo: (_, { id }) => {
const todo = todos.find(t => t.id === id);
todo.completed = !todo.completed;
return todo;
},
},
};

const server = new ApolloServer({ typeDefs, resolvers });
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});






Step 2: Set Up the React App (Frontend)




npx create-react-app graphql-todo
cd graphql-todo
npm install @apollo/client graphql






in src/index.js




import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';

const client = new ApolloClient({
uri: 'http://localhost:4000',
cache: new InMemoryCache(),
});

ReactDOM.render(
<ApolloProvider client={client}>
<App />
</ApolloProvider>,
document.getElementById('root')
);






in src/App.js




import React, { useState } from 'react';
import { useQuery, useMutation, gql } from '@apollo/client';

const GET_TODOS = gql`
query {
todos {
id
title
completed
}
}
`;

const ADD_TODO = gql`
mutation($title: String!) {
addTodo(title: $title) {
id
title
completed
}
}
`;

const TOGGLE_TODO = gql`
mutation($id: ID!) {
toggleTodo(id: $id) {
id
completed
}
}
`;

function App() {
const { data, loading } = useQuery(GET_TODOS);
const [addTodo] = useMutation(ADD_TODO, {
refetchQueries: [{ query: GET_TODOS }],
});
const [toggleTodo] = useMutation(TOGGLE_TODO);
const [input, setInput] = useState('');

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

const handleAdd = () => {
if (input.trim()) {
addTodo({ variables: { title: input } });
setInput('');
}
};

return (
<div style={{ padding: '2rem' }}>
<h2>📝 GraphQL ToDo List</h2>
<input value={input} onChange={e => setInput(e.target.value)} placeholder="New task" />
<button onClick={handleAdd}>Add</button>
<ul>
{data.todos.map(todo => (
<li key={todo.id} onClick={() => toggleTodo({ variables: { id: todo.id } })}>
<span style={{ textDecoration: todo.completed ? 'line-through' : 'none' }}>
{todo.title}
</span>
</li>
))}
</ul>
</div>
);
}

export default App;







Step 3 : Start the app

in backend




node index.js






in frontend




npm start  






🚀 You Did It!

You now have a working React app powered by GraphQL. You can:




  1. View todos

  2. Add a new task

  3. Toggle them done/undone



What's Next?




  • Add delete functionality

  • Store data in MongoDB or PostgreSQL

  • Deploy to Vercel or Netlify

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Build a Simple ToDo App with React and GraphQL

Thematisch verwandte Begriffe: Build, Simple, ToDo, with · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-59815 | Joplin is an open source note-taking and to-do application that organise…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick