Coder Social home page Coder Social logo

ayalon / nuxt-graphql-middleware Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dulnan/nuxt-graphql-middleware

0.0 1.0 0.0 4.98 MB

GraphQL in the backend, fetch in the frontend. With TypeScript support.

Home Page: https://nuxt-graphql-middleware.dulnan.net

License: MIT License

JavaScript 0.22% TypeScript 84.65% Vue 15.12%

nuxt-graphql-middleware's Introduction

nuxt-graphql-middleware banner

Nuxt GraphQL Middleware

Expose GraphQL queries and mutations as fully typed API routes.

Documentation โ€“ npm โ€“ Version 2.x (for Nuxt 2)

Test

Features

  • Exposes each query and mutation as an API route
  • GraphQL requests are only done on the server side
  • No GraphQL documents in client bundle
  • Includes composables to perform queries or mutations
  • Modify request headers, responses and handle errors
  • HMR for all GraphQL files
  • Integration with Nuxt DevTools
  • Full TypeScript integration for schema, queries, mutations and fragments using graphql-code-generator

Setup

Install

npm install --save nuxt-graphql-middleware

Minimal configuration needed:

export default defineNuxtConfig({
  modules: ['nuxt-graphql-middleware'],
  graphqlMiddleware: {
    graphqlEndpoint: 'https://example.com/graphql',
  },
})

Usage

Write your first query, e.g. in pages/films.query.graphql:

query films {
  allFilms {
    films {
      id
    }
  }
}

Your query is now available via the useGraphqlQuery() composable:

const { data } = await useGraphqlQuery('films')
console.log(data.allFilms.films)

Alternatively you can also call http://localhost:3000/api/graphql_middleware/query/films to get the same result.

Nuxt 2

The 3.x releases are only compatible with Nuxt 3. The 2.x branch and releases on npm are compatible with Nuxt 2.

nuxt-graphql-middleware's People

Contributors

dulnan avatar ayalon avatar milanbombschliip avatar danielroe 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.