Skip to content

Commit

Permalink
Merge pull request #47 from haodt/feat/upgrade-to-apollo-v3
Browse files Browse the repository at this point in the history
Upgrade to apollo v3
  • Loading branch information
ihorkatkov authored Jan 14, 2021
2 parents c62e6b8 + e6ca485 commit 08737cc
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 105 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.16.0
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"arrowParens": "avoid",
"trailingComma": "all"
}
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
"prepublish": "npm run compile"
},
"dependencies": {
"apollo-client": "^2.0.4",
"apollo-link": "^1.0.7",
"apollo-link-http": "^1.3.2",
"apollo-link-http-common": "^0.2.4",
"graphql": "0.11.3",
"@apollo/client": "^3.0.0",
"graphql": "^15.0.0",
"rxjs": "~6.2.2"
},
"devDependencies": {
Expand All @@ -30,7 +27,6 @@
"eslint": "^4.14.0",
"eslint-plugin-prettier": "^2.4.0",
"fetch-mock": "^6.5.2",
"graphql-tag": "^2.9.2",
"jest": "^22.2.1",
"node-fetch": "^2.2.0",
"prettier": "1.9.2",
Expand Down
9 changes: 6 additions & 3 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createUploadMiddleware } from '../index'
import fetchMock from 'fetch-mock'
import { execute } from 'apollo-link'
import gql from 'graphql-tag'
import { execute, gql } from '@apollo/client/core'

import { createUploadMiddleware } from '../index'

jest.mock('../request')
jest.mock('../extractFiles')
Expand Down Expand Up @@ -46,6 +46,7 @@ describe('#createUploadMiddleware', () => {
expect(forward).toHaveBeenCalledTimes(0)
expect(result.headers).toEqual(headers)
})

it('should pass headers from options', () => {
const headers = { authorization: '1234' }
const { request } = createUploadMiddleware({
Expand All @@ -59,6 +60,7 @@ describe('#createUploadMiddleware', () => {

expect(result.headers).toEqual(headers)
})

it('should combine headers from options and context', () => {
const optionsHeaders = { 'x-spree-token': 'token' }
const contextHeaders = { authorization: '1234' }
Expand All @@ -75,6 +77,7 @@ describe('#createUploadMiddleware', () => {
Object.assign({}, contextHeaders, optionsHeaders),
)
})

it('uses custom fetch function', done => {
const variables = { params: 'stub' }
fetchMock.post('begin:http://data/', makePromise(data))
Expand Down
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { HttpLink } from 'apollo-link-http'
import { ApolloLink, concat } from 'apollo-link'
import {
HttpLink,
ApolloLink,
concat,
parseAndCheckHttpResponse,
Observable,
} from '@apollo/client/core'
import { print } from 'graphql/language/printer'

import request from './request'
import extractFiles from './extractFiles'
import { isObject } from './validators'
import { parseAndCheckHttpResponse } from 'apollo-link-http-common'
import { Observable } from 'apollo-link'

export const createUploadMiddleware = ({ uri, headers, fetch, credentials }) =>
new ApolloLink((operation, forward) => {
Expand Down
Loading

0 comments on commit 08737cc

Please sign in to comment.