<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ian h</title>
    <description>The latest articles on DEV Community by ian h (@ianh).</description>
    <link>https://dev.to/ianh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F365539%2F979d2470-9dc2-4a9c-8a71-b1d4d0e70eb1.png</url>
      <title>DEV Community: ian h</title>
      <link>https://dev.to/ianh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ianh"/>
    <language>en</language>
    <item>
      <title>GraphQL on Next.js + Zeit Serverless Functions</title>
      <dc:creator>ian h</dc:creator>
      <pubDate>Mon, 20 Apr 2020 14:27:47 +0000</pubDate>
      <link>https://dev.to/ianh/graphql-on-zeit-serverless-functions-2d4m</link>
      <guid>https://dev.to/ianh/graphql-on-zeit-serverless-functions-2d4m</guid>
      <description>&lt;p&gt;I was a bit surprised that there wasn't a library dedicated to running GraphQL on Next.js. It's not terribly hard to do, but I just found myself copying code from project to project enough that it warrants its own library.&lt;/p&gt;

&lt;p&gt;Announcing next-graphql, a drop-in solution for running GraphQL on Next.js (and Zeit Serverless Functions): &lt;a href="https://github.com/ian/next-graphql"&gt;https://github.com/ian/next-graphql&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're unfamiliar with how Zeit Serverless Functions work, here's the announcement: &lt;a href="https://zeit.co/docs/v2/serverless-functions/introduction"&gt;https://zeit.co/docs/v2/serverless-functions/introduction&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In it's simplest form it's a 1-page implementation by adding a &lt;code&gt;api/graphql.js&lt;/code&gt; (or &lt;code&gt;pages/api/graphql.js&lt;/code&gt; for next.js).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createHandler } from "next-graphql"

let ITEMS = [
  { name: "First" }
]

const typeDefs = `
  type Item {
    name: String! 
  }

  type Query {
    getItems: [Item]!
  }

  type Mutation {
    createItem(name:String!): Item!
  }
`

const resolvers = {
  Query: {
    getItems: async () =&amp;gt; {
      return db
    },
  },
  Mutation: {
    createItem: async (obj, { name }) =&amp;gt; {
      const item = { name }
      ITEMS.push(item)
      return item
    }
  }
}

export default createHandler({
  typeDefs,
  resolvers,
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>zeit</category>
      <category>graphql</category>
      <category>serverless</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
