Apollo-link: apollo-link-batch-http ์‚ฌ์šฉ์ž๊ฐ€ ์ผ๊ด„ ์ฒ˜๋ฆฌํ•  ์š”์ฒญ์„ ๊ฒฐ์ •ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2018๋…„ 01์›” 07์ผ  ยท  2์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: apollographql/apollo-link

_apollo-link-batch-http_๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํŠน์ • ์‹œ๊ฐ„ ๊ฐ„๊ฒฉ์˜ ๋ชจ๋“  ์š”์ฒญ์ด ์ผ๊ด„์ ์œผ๋กœ ํ˜ธ์ถœ๋ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ๋Œ€๋ถ€๋ถ„์˜ ์š”์ฒญ์ด ๋น ๋ฅด์ง€๋งŒ ์‹œ๊ฐ„์ด ๋งŽ์ด ๊ฑธ๋ฆฌ๋Š” ์š”์ฒญ๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์•Œ๋ ค์ง„ ๋Š๋ฆฐ ์š”์ฒญ์„ ๋‹ค๋ฅธ ์š”์ฒญ๊ณผ ์ผ๊ด„ ์ฒ˜๋ฆฌํ•˜๋ฉด ์ด์ œ ๋ชจ๋“  ์š”์ฒญ์ด ๊ฐ€์žฅ ๋Š๋ฆฐ ์š”์ฒญ๊ณผ ๋™์ผํ•œ ์‘๋‹ต ์‹œ๊ฐ„์„ ๊ฐ–๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ์ €ํ•˜๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์š”์ฒญ์ด ์ฆ‰์‹œ ์ผ๊ด„ ์ฒ˜๋ฆฌ๋˜์–ด์•ผ ํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์ฝœ๋ฐฑ์ด ์žˆ์œผ๋ฉด ์ข‹์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๋ถ„ํ• ๋กœ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
__links.js__

const batchHttpLink = new BatchHttpLink({
  fetch: createApolloFetch({
    constructOptions,
    uri: process.env.REACT_APP_API_ENDPOINT,
  }),
})

const normalHttpLink = createHttpLink({
  uri: '/graphql',
  credentials: 'same-origin',
})

export split(({getContext}) => getContext().noBatch, normalHttpLink, batchHttpLink)

์ผ๊ด„ ๋งํฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ฟผ๋ฆฌ ๋งŒ๋“ค๊ธฐ

const ProfileWithData = graphql(CurrentUserForLayout, {
  options: { 
    context: { noBatch: true }
  },
})(Profile);

์—ฌ๊ธฐ์—์„œ ์ปจํ…์ŠคํŠธ์—์„œ noBatch ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฟผ๋ฆฌ๋ฅผ ์ผ๊ด„ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ์ œ์–ดํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋“  ์ฟผ๋ฆฌ๋Š” ์ผ๊ด„ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  2 ๋Œ“๊ธ€

๋ถ„ํ• ๋กœ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
__links.js__

const batchHttpLink = new BatchHttpLink({
  fetch: createApolloFetch({
    constructOptions,
    uri: process.env.REACT_APP_API_ENDPOINT,
  }),
})

const normalHttpLink = createHttpLink({
  uri: '/graphql',
  credentials: 'same-origin',
})

export split(({getContext}) => getContext().noBatch, normalHttpLink, batchHttpLink)

์ผ๊ด„ ๋งํฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ฟผ๋ฆฌ ๋งŒ๋“ค๊ธฐ

const ProfileWithData = graphql(CurrentUserForLayout, {
  options: { 
    context: { noBatch: true }
  },
})(Profile);

์—ฌ๊ธฐ์—์„œ ์ปจํ…์ŠคํŠธ์—์„œ noBatch ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฟผ๋ฆฌ๋ฅผ ์ผ๊ด„ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ์ œ์–ดํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋“  ์ฟผ๋ฆฌ๋Š” ์ผ๊ด„ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค.

@charleyw ์˜ ์˜ˆ์— ๊ฐ์‚ฌ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์งˆ๋ฌธ์— ๋Œ€ํ•œ ๋‹ต๋ณ€์ด ๋œ ๊ฒƒ

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰