Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GraphiQL to v2.0.9 #895

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions examples/subscription/memory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'use strict'

const mercurius = require('../..')
const Fastify = require('fastify')

const app = Fastify({ logger: { level: 'debug' } })

// list of products
const products = []

// graphql schema
const schema = `
type Product {
name: String!
state: String!
}

type Query {
products: [Product]
}

type Mutation {
addProduct(name: String!, state: String!): Product
}

type Subscription {
productAdded: Product
}
`

// graphql resolvers
const resolvers = {
Query: {
products: () => products
},
Mutation: {
addProduct: async (_, { name, state }, { pubsub }) => {
const product = { name, state }

products.push(product)

pubsub.publish({
topic: 'new_product_updates',
payload: {
productAdded: product
}
})

return product
}
},
Subscription: {
productAdded: {
subscribe: async (_, __, { pubsub }) => {
return await pubsub.subscribe('new_product_updates')
}
}
}
}

// server start
const start = async () => {
try {
// register GraphQl
app.register(mercurius, {
schema,
resolvers,
graphiql: true,
subscription: {
async onConnect ({ payload }) {
app.log.info({ payload }, 'connection_init data')
return true
}
}
})

// start server
await app.listen({ port: 3000 })
} catch (error) {
app.log.error(error)
}
}

start()
4 changes: 2 additions & 2 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function render () {

function importDependencies () {
const link = document.createElement('link')
link.href = 'https://unpkg.com/graphiql@2.0.2/graphiql.min.css'
link.href = 'https://unpkg.com/graphiql@2.0.9/graphiql.min.css'
link.type = 'text/css'
link.rel = 'stylesheet'
link.media = 'screen,print'
Expand All @@ -52,7 +52,7 @@ function importDependencies () {
return importer.urls([
'https://unpkg.com/react@18.2.0/umd/react.production.min.js',
'https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js',
'https://unpkg.com/graphiql@2.0.2/graphiql.min.js'
'https://unpkg.com/graphiql@2.0.9/graphiql.min.js'
])
}

Expand Down
6 changes: 3 additions & 3 deletions static/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

self.addEventListener('install', function (e) {
e.waitUntil(
caches.open('graphiql-v2.0.2').then(function (cache) {
caches.open('graphiql-v2.0.9').then(function (cache) {
return cache.addAll([
'./main.js',
'https://unpkg.com/graphiql@2.0.2/graphiql.css',
'https://unpkg.com/graphiql@2.0.9/graphiql.css',
'https://unpkg.com/react@18.2.0/umd/react.production.min.js',
'https://unpkg.com/react-dom@18.2.0/umd/react-dom.production.min.js',
'https://unpkg.com/graphiql@2.0.2/graphiql.min.js'
'https://unpkg.com/graphiql@2.0.9/graphiql.min.js'
])
})
)
Expand Down