DEV Community

Debbie O'Brien
Debbie O'Brien

Posted on

7 1

GraphQL and Nuxt

We need to use the graphql-tag to be able to add our query so first we import this

import gql from 'graphql-tag'
Enter fullscreen mode Exit fullscreen mode

We can then make our query listing all the data that we want to receive and ordering by what we prefer. Here we just added an export const called workshop and make it equal to our gql tag which has a query called workshops and that queries the workshops table.

export const workshops = gql`
  query workshops {
    workshops(order_by: { date: desc }) {
      date
      title
      year
    }
  }
`
Enter fullscreen mode Exit fullscreen mode

Then we need to use apollo so that we can get our data to our template. Don't forget to first install '@nuxtjs/apollo', and then add to the modules of our next config.

apollo: {
    $loadingKey: 'loading',
    workshops: {
      query: workshops,
    },
  },
Enter fullscreen mode Exit fullscreen mode

And now we can do a v-for over all our data and print the title for example

<div v-for="(workshop, index) in workshops" :key="index" class="flex">
  <p>{{workshop.title}}</p>
</div>  
Enter fullscreen mode Exit fullscreen mode

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

Top comments (7)

Collapse
 
afflexux profile image
afflexux

Thanks Debbie, I've just built my (as yet fairly sparse) blog out with Nuxt and Cockpit CMS.

Cockpit has a GraphQL plugin, think I'll have a go at incorporating it when I get a chance.

Collapse
 
bastianhilton profile image
Sebastian hilton

i'm working on adding cockpit to my tech stack, any luck with getting it going so far with Nuxtjs?

Collapse
 
afflexux profile image
afflexux

Yeah it works a treat.

I mostly followed this:
willbrowning.me/building-a-static-...

If you need any help give me a shout, I could probably make my final repo public once I’ve double checked I’ve properly stashed away all my keys!

Collapse
 
knth profile image
KNTH

Hi Debbie,

I am using GraphQL with Nuxt and Apollo using apollo-composable (instead of @nuxtjs/apollo) and it's very nice.

As of lack of documentation, I struggle with knowing exactly how to proceed to implement a good testing suit using Apollo cache instead of Vuex. If you had any resources to share it'd be helpful 🙏

Thanks for your daily writing.

Collapse
 
debs_obrien profile image
Debbie O'Brien

emm, not sure I have come across any but will be doing some more work on this in the future.

Collapse
 
manuelehrenfeld profile image
Manuel Ehrenfeld

Hi Debbie,
is it possible to use GraphQL queries without the @nuxtjs/apollo module? if so, Is there any documentation on how to implement it? in my case I'm using the @nuxt/strapi module.
Thanks!

Collapse
 
debs_obrien profile image
Debbie O'Brien

there is. I created a plugin but haven't finished writing the blog post. Really should write and publish it but yes a simple plugin is possible

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay