μλ νμΈμ:
react-apollo
codesandbox μ κΈ°λ³Έ ꡬμ±μΌλ‘ apollo-link-rest
μμ νκ² μ΅λλ€ .
TV νλ‘κ·Έλ¨ λͺ©λ‘μ νμνλ λμ μΈν°νμ΄μ€μ : Network error: Failed to execute 'fetch' on 'Window': Invalid credentials mode
μ€λ₯κ° νμλ©λλ€.
λ΄ μμ μ create-react-app
νκ²½μμ ν΄λΉ μ½λλ₯Ό 볡μ ν λ Apollo DevToolsμμ μμ²μ μ€νν λ λ€μ μ€λ₯κ° λ°μνμ΅λλ€.
{
"errors": [
{
"message": "forward is not a function",
"locations": [
"TypeError: forward is not a function\n at RestLink../node_modules/apollo-link-rest/bundle.umd.js.RestLink.request (http://localhost:3000/static/js/bundle.js:21028:20)\n at http://localhost:3000/static/js/bundle.js:19809:33\n at ApolloLink.request (http://localhost:3000/static/js/bundle.js:17407:12)\n at ApolloLink.request
}
]
}
μ΄ λ§ν¬μ λν μμ μ κ°μ¬λ립λλ€! REST APIλ₯Ό μ¬μ©νλ μ¬λλ€μ μν΄ GraphQLκ³Ό μ μ¬ν κΈ°λ₯μ μ 곡ν¨μΌλ‘μ¨ REST μμ μ ν¨μ¬ λ μ½κ² κ΄λ¦¬ ν μ ββμμ΅λλ€.
@sinisterra μ±μμ forward is not a function
λ₯Ό λ³Ό λ μΌλ°μ μΌλ‘ λ
Έλ μ€ νλμμ @client
λλ @rest(β¦)
μ§μλ¬Έμ μμ κΈ° λλ¬Έμ
λλ€. λΉμ μμν κ²½μ°μ
λκΉ?
fetch
μ€λ₯μ κ΄λ ¨νμ¬ μ΄λ€ λΈλΌμ°μ μμ ν
μ€νΈνκ³ μμ΅λκΉ?
@fbartho μλμ, μμ μ λκ°μ 쿼리λ₯Ό μ€ννκ³ μμ΅λλ€. @rest
μ§μλ¬Έμ΄ μ λλ‘ μ μ©λκ³ μμ΅λλ€. Google Chrome 67.0.3396.62λ₯Ό μ¬μ©νκ³ μμ΅λλ€. Firefox 60.0.1μμ μμ λ₯Ό μ€ννλ €κ³ νμ λ μ€ν¨νμ§λ§ λ€λ₯Έ μ€λ₯ : Network error: 'credentials' member of RequestInit 'null' is not a valid value for enumeration RequestCredentials.
κΉ¨μ§ μ λΏλ§μ΄ μλλλ€! μ΄ λ¬Έμ λ λ§€μ° μ€μνλ€κ³ μκ°ν©λλ€.
λλ λν apollo-link-restλ₯Ό μ¬μ©νμ¬ μ§λ λͺ λ¬ λμ μ μλνλ νλ‘λμ
νκ²½μμ λμΌν μ€λ₯κ° λ°μν©λλ€. μ΄κ²μ΄ λΈλΌμ°μ μ
λ°μ΄νΈ λλ¬ΈμΈ κ² κ°μ΅λλ€.
ν¬λ‘¬ Version 67.0.3396.79 (Official Build) (64-bit)
κ°μ λ¬Έμ κ° μ¬ν리μ νμ΄μ΄ νμ€μμ μΌμ΄λκ³ μμ΅λλ€. λλ κ·Έκ²μ μμ ν μ»μ§ λͺ»ν©λλ€. 5 μ 24 μΌ μ΄νλ‘ λμΌν λ²μ μ λ΄ μμ© νλ‘κ·Έλ¨μ΄ μ μλνμ΅λλ€.
μλνλ customFetch fnμ ꡬμ±νμ§λ§ apollo-link-restλ‘ μννλ μμ²μμλ§ λ°μν©λλ€. Β―_ (γ) _ / Β―
customFetch
ꡬμ±μ μ κ±° ν λλ λμΌν μ€λ₯κ° λ°μν©λλ€.
μ€μ λ‘ λ¬Έμ λ₯Ό λ°κ²¬νμ΅λλ€.
customFetch
ν¨μλ₯Ό μ¬μ©νκ³ μλλ°,μ΄ ν¨μλ apollo-link-rest
μμ μ΅μ
λ§€κ° λ³μ credentials: null
μ ν¨κ» νΈμΆλ©λλ€. μ΄λ‘ μΈν΄ μ λ²μ μ ν¬λ‘¬μ ν¬ν¨ν λͺ¨λ λΈλΌμ°μ μμμ΄ μ€λ₯κ° λ°μν©λλ€.
μ격 μ¦λͺ μ μ¬μ©νμ§ μκΈ° λλ¬Έμ λ΄ μ¬μ©μ μ§μ κ°μ Έ μ€κΈ° κΈ°λ₯μ λν λΉ λ₯Έ μμ μ λ€μκ³Ό κ°μ΅λλ€.
export function fetchWithAuth(url, options = {}) {
// this fixes apollo-link-rest providing credentials: null options
const { credentials, ...opt } = options
return fetch(url, getOptions(opt));
}
λν "λ€νΈμν¬ μ€λ₯ : Failed to Fetch"κ° λ°μνμ¬ μΏΌλ¦¬κ° apollo-link-restλ‘ μ€νλλ κ²μ λ§μ λ²½μ 머리λ₯Ό λΆλͺ νμ΅λλ€. @JuHwon μ΄ λ§μ΅λλ€. μ΄κ²μ RestLink μμ±μμ μ격 μ¦λͺ μ΅μ κ³Ό μ°κ²°λ κ²μΌλ‘ 보μ λλ€. μ΄μ μλ λ¬Έμμ λ°λΌ μ ν μ¬νμΌλ‘ μλνμ§λ§ μ΄μ λ λ€μκ³Ό κ°μ μ΅μ μ ν¬ν¨ν΄μΌλ§ μλ ν μ μμ΅λλ€.
const restLink = new RestLink({
uri: ${process.env.REACT_APP_API_URL}/,
credentials: 'same-origin', // eg. or credentials: 'omit', etc
});
v0.3.1μμ μμ λμ΄μΌν©λλ€-μ΄μ μ¬μ© κ°λ₯ν©λλ€!
κ°μ₯ μ μ©ν λκΈ
v0.3.1μμ μμ λμ΄μΌν©λλ€-μ΄μ μ¬μ© κ°λ₯ν©λλ€!