Giter Site home page Giter Site logo

echo-two's Introduction

Astro with GraphQL

In this example repo, you get the bare bones Astro starter pack, coupled with a simple GraphQL implementation using GraphQL Yoga and Apollo Client.

Astro is set to SSR mode to enable its API endpoint abilities, necessary to handle incoming GraphQL requests.

For a full walkthrough and tutorial on this project, check out this blog post on my website.

๐Ÿš€ Project Structure

Inside of your Astro project, you'll see the following folders and files:

/
โ”œโ”€โ”€ public/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ components/
โ”‚       โ””โ”€โ”€ CartRow.astro
โ”‚   โ””โ”€โ”€ data/
โ”‚       โ””โ”€โ”€ cart.ts
โ”‚       โ””โ”€โ”€ types.ts
โ”‚   โ””โ”€โ”€ lib/
โ”‚       โ””โ”€โ”€ apollo-client.ts
โ”‚   โ””โ”€โ”€ styles/
โ”‚       โ””โ”€โ”€ main.css
โ”‚   โ””โ”€โ”€ pages/
โ”‚       โ””โ”€โ”€ index.astro
โ”‚     โ””โ”€โ”€ api/
โ”‚         โ””โ”€โ”€ graphql.ts
โ””โ”€โ”€ package.json

Astro looks for .astro or .md files in the src/pages/ directory. Each page is exposed as a route based on its file name. This project just has the one page, a homepage, located at /pages/index.astro.

There's nothing special about src/components/, but that's where you can put any Astro/React/Vue/Svelte/Preact components.

The src/data directory holds some types and dummy data we can use with GraphQL.

In src/lib there's a really simple implemenation of Apollo Client, used to physically call our GraphQL endpoint.

With the /src/pages/api/graphql.ts file, this is where the GraphQL action happens. It uses GraphQL Yoga to create a schema, and defines a POST endpoint to handle incoming API requests.

echo-two's People

Contributors

hillonyechekwa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.