diff --git a/example/graphql/graphql.gql b/example/graphql/graphql.gql new file mode 100644 index 0000000..5e64729 --- /dev/null +++ b/example/graphql/graphql.gql @@ -0,0 +1,13 @@ +query country( $code: ID! ) { + country( code: $code ) { + name + native + capital + emoji + currency + languages { + code + name + } + } +} diff --git a/example/graphql/graphql.json b/example/graphql/graphql.json new file mode 100644 index 0000000..781b91e --- /dev/null +++ b/example/graphql/graphql.json @@ -0,0 +1,7 @@ +{ + "query": "query country($code: ID!) {\n country(code: $code) {\n name\n native\n capital\n emoji\n currency\n languages {\n code\n name\n }\n }\n }", + "variables": { + "code": "IT" + }, + "operationName": "country" +} diff --git a/example/graphql/index.js b/example/graphql/index.js index 8d47168..cd5f65f 100644 --- a/example/graphql/index.js +++ b/example/graphql/index.js @@ -1,3 +1,3 @@ -import * as USERS from './users.json'; +import * as GRAPHQL from './graphql.json'; -export { USERS }; +export { GRAPHQL }; diff --git a/example/graphql/users.gql b/example/graphql/users.gql deleted file mode 100644 index c92ee15..0000000 --- a/example/graphql/users.gql +++ /dev/null @@ -1,16 +0,0 @@ -query allUsers($first: Int) { - allUsers(first: $first) { - id - name - createdAt - email - comments { - id - text - } - posts { - id - title - } - } -} diff --git a/example/graphql/users.json b/example/graphql/users.json deleted file mode 100644 index 9842aa3..0000000 --- a/example/graphql/users.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "query": "query allUsers($first: Int) {\n allUsers(first: $first) {\n id\n name\n createdAt\n email\n comments {\n id\n text\n }\n posts {\n id\n title\n }\n }\n }", - "variables": { - "first": 10 - }, - "operationName": "allUsers" -} diff --git a/example/nuxt.config.js b/example/nuxt.config.js index 4ee7c48..7608a0b 100644 --- a/example/nuxt.config.js +++ b/example/nuxt.config.js @@ -1,7 +1,7 @@ import { resolve } from 'path'; import * as PACKAGE from '../package.json'; -import { USERS } from './graphql'; +import { GRAPHQL } from './graphql'; const meta = [ { @@ -43,11 +43,12 @@ export default { }, // GraphQL { - endpoint: 'https://api.graph.cool/simple/v1/ciyz901en4j590185wkmexyex', + endpoint: 'https://countries.trevorblades.com/', method: 'post', - field: 'users', - pathToData: 'data.allUsers', - body: USERS, + field: 'graphql', + pathToData: 'data.country', + emptyValue: {}, + body: GRAPHQL, }, ], }, diff --git a/example/pages/index.vue b/example/pages/index.vue index e2411e5..42cd10e 100644 --- a/example/pages/index.vue +++ b/example/pages/index.vue @@ -7,29 +7,34 @@

Total number of comments preloaded:

-

- +

+

Total number of posts preloaded:

-

- +

+

-
+

- Total number of users preloaded: + Total number graphql data preloaded:

-

- -

+ +
+            
         
- - diff --git a/example/store/build-data.js b/example/store/build-data.js index 902dd1c..c2b2201 100644 --- a/example/store/build-data.js +++ b/example/store/build-data.js @@ -1,3 +1,4 @@ +// Import the generated data const getFile = () => import( '~/apis-to-file/data.json' ).then( @@ -12,7 +13,7 @@ export const actions = { let preloadedComments = [] , preloadedPosts = [] - , preloadedUsers = [] + , preloadedGraphQl = [] ; try { @@ -20,15 +21,15 @@ export const actions = { const { comments, posts, - users, + graphql, } = await getFile(); if( comments ) preloadedComments = comments; if( posts ) preloadedPosts = posts; - if( users ) - preloadedUsers = users; + if( graphql ) + preloadedGraphQl = graphql; } catch( e ) { @@ -57,8 +58,8 @@ export const actions = { ); commit( - 'users/SET_ITEMS', - preloadedUsers, + 'graphql/SET_ITEMS', + preloadedGraphQl, { root: true, } diff --git a/example/store/comments.js b/example/store/comments.js index 1c69c02..8815ed5 100644 --- a/example/store/comments.js +++ b/example/store/comments.js @@ -10,9 +10,7 @@ export const mutations = { items, ) { - state.items = Object.freeze( - items, - ); + state.items = items; }, }; diff --git a/example/store/users.js b/example/store/graphql.js similarity index 54% rename from example/store/users.js rename to example/store/graphql.js index 1c69c02..375b52e 100644 --- a/example/store/users.js +++ b/example/store/graphql.js @@ -1,18 +1,16 @@ export const state = () => ( { - items: [], + data: {}, } ); export const mutations = { SET_ITEMS( state, - items, + value, ) { - state.items = Object.freeze( - items, - ); + state.data = value; }, }; diff --git a/example/store/posts.js b/example/store/posts.js index 1c69c02..8815ed5 100644 --- a/example/store/posts.js +++ b/example/store/posts.js @@ -10,9 +10,7 @@ export const mutations = { items, ) { - state.items = Object.freeze( - items, - ); + state.items = items; }, }; diff --git a/test/module.test.js b/test/module.test.js index 0506723..f226193 100644 --- a/test/module.test.js +++ b/test/module.test.js @@ -1,7 +1,10 @@ +// Test utils import { setup, get, } from '@nuxtjs/module-test-utils'; + +// Dom import { JSDOM } from 'jsdom'; // Nuxt config @@ -11,8 +14,8 @@ const BASE_URL = '/'; config.dev = false; config.router.base = BASE_URL; -config.server.host = 'localhost'; +// Tests describe( 'module', () => { @@ -31,7 +34,7 @@ describe( ); }, - 60000 + 90000 ); afterAll( @@ -73,7 +76,7 @@ describe( ) , { window } = new JSDOM( html - ).window + ) , element = window.document.querySelector( selector ) @@ -118,7 +121,7 @@ describe( ); test( - 'comments', + 'posts', async() => { await getElement( @@ -130,12 +133,17 @@ describe( ); test( - 'users', + 'graphql', async() => { - await getElement( - '.users', - 10, + const html = await get( + BASE_URL + ); + + expect( + html + ).toContain( + 'Italy' ); }