Skip to content

Commit

Permalink
Merge pull request #8 from nyawach/feature/add-apollo-client
Browse files Browse the repository at this point in the history
apollo-client 投げれるようにするまで
  • Loading branch information
nyawach committed Feb 18, 2022
2 parents 14ce66d + daed902 commit 942d0b7
Show file tree
Hide file tree
Showing 23 changed files with 3,747 additions and 144 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions 0022-nuxt-bridge/frontend/assets/apollo/getTest.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
query getTest {
launchesPast(limit: 10) {
mission_name
launch_date_local
launch_site {
site_name_long
}
links {
article_link
video_link
}
rocket {
rocket_name
first_stage {
cores {
flight
core {
reuse_count
status
}
}
}
second_stage {
payloads {
payload_type
payload_mass_kg
payload_mass_lbs
}
}
}
ships {
name
home_port
image
}
}
}
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions 0022-nuxt-bridge/frontend/assets/util/createApolloClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NuxtAppOptions } from '@nuxt/types'
import { createHttpLink } from 'apollo-link-http'
import fetch from 'isomorphic-fetch'

export default (uri: string, app: NuxtAppOptions) => ({
defaultHttpLink: false,
link: createHttpLink({
uri,
credentials: 'same-origin',
fetch: async (uri: string, options) => {
return fetch(uri, options)
},
}),
})
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export default defineNuxtConfig({
strategy: 'no_prefix',
},

apollo: {
clientConfigs: {
default: '~/plugins/apollo-client.ts',
},
},

// Global CSS: https://go.nuxtjs.dev/config-css
css: [],

Expand All @@ -67,8 +73,15 @@ export default defineNuxtConfig({
buildModules: [],

// Modules: https://go.nuxtjs.dev/config-modules
modules: ['@nuxtjs/i18n'],
modules: [
'@nuxtjs/i18n',
'@nuxtjs/apollo',
],

// Build Configuration: https://go.nuxtjs.dev/config-build
build: {},

alias: {
tslib: 'tslib/tslib.es6.js'
}
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "demo",
"type": "module",
"version": "1.0.0",
"private": true,
"scripts": {
Expand All @@ -13,7 +14,15 @@
"test": "jest"
},
"dependencies": {
"@nuxtjs/apollo": "^4.0.1-rc.5",
"@types/isomorphic-fetch": "^0.0.35",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
"apollo-link-http": "^1.5.17",
"core-js": "^3.19.3",
"graphql": "^16.3.0",
"graphql-tag": "^2.12.6",
"isomorphic-fetch": "^3.0.0",
"nuxt-edge": "latest",
"vue": "^2.6.14",
"vue-server-renderer": "^2.6.14",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<template lang="pug">
main
Tutorial
main
Tutorial
</template>

<script lang="ts">
import Vue from 'vue'
import Tutorial from '~/components/Tutorial.vue'
import getTest from '~/assets/apollo/getTest.gql'
export default Vue.extend({
name: 'IndexPage',
components: {
Tutorial,
},
apollo: {
test: {
query: getTest,
result(res: object) {
console.log(res)
}
}
},
})
</script>

Expand Down
4 changes: 4 additions & 0 deletions 0022-nuxt-bridge/frontend/plugins/apollo-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Context } from '@nuxt/types'
import createApolloClient from '~/assets/util/createApolloClient'

export default ({ app }: Context) => createApolloClient('https://api.spacex.land/graphql', app)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"~/*": ["./*"],
"@/*": ["./*"]
},
"types": ["@nuxt/types", "@types/node", "@nuxtjs/i18n"]
"types": ["@nuxt/types", "@types/node", "@nuxtjs/i18n", "vue-apollo", "~/types/*"]
},
"exclude": ["node_modules", ".nuxt", "dist"]
}
13 changes: 13 additions & 0 deletions 0022-nuxt-bridge/frontend/types/gql.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare module '*.gql' {
import { DocumentNode } from 'graphql'

const content: DocumentNode
export default content
}

declare module '*.graphql' {
import { DocumentNode } from 'graphql'

const content: DocumentNode
export default content
}
Loading

0 comments on commit 942d0b7

Please sign in to comment.