🤍 전 강의 25% 할인 중 🤍

2024년 상반기를 돌아보고 하반기에도 함께 성장해요!
인프런이 준비한 25% 할인 받으러 가기 >>

  • 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    해결됨

useMutation에러

23.08.10 03:32 작성 조회수 303

0

Server Error

Invariant Violation: Argument of undefined passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert your operation into a document

This error happened while generating the page. Any console logs will be displayed in the terminal window.

 

이러한 에러가 뜨는데 왜 발생하는 걸까요.

const [contents, setContents] = useState("");
  18 | 
> 19 |     const [나의함수] = useMutation(나의그래프큐엘셋팅)
     |                               ^
  20 | 
  21 |     const onClickSubmit = async () => {
  22 |         const result = await 나의함수({

 

 

 

 

 


 

import { useState } from "react"
import {나의그래프큐엘셋팅} from './BoardWrite.queries' // export는 골라서 가져오기
import BoardWriterUI from "./BoardWrite.presenter"; // export-default로 한 개만 가져오기
import { useMutation } from "@apollo/client";
// import BoardWriterUI from "./BoardWrite.presenter"; // export-default로 한 개만 가져오기
// import BoardWriterUI, {apple} from "./BoardWrite.presenter"; // export-default와 export 함께 가져오기
// import * as S from './BoardWrite.styles' // 모든 export를 가져와줘
// S.BlueButton
// S.RedInput
 


export default function BoardWrite() {

    const [writer, setWriter] = useState("");
    const [title, setTitle] = useState("");
    const [contents, setContents] = useState("");

    const [나의함수] = useMutation(나의그래프큐엘셋팅)

    const onClickSubmit = async () => {
        const result = await 나의함수({
            variables : {                // variables 이게 $ 역활을 함
                writer : writer,
                title : title,
                contents : contents
            }
        })
        console.log(result)
    }

    const onChangeWriter = (event) => {
        setWriter(event.target.value)
    }

    const onChangeTitle = (event) => {
        setTitle(event.target.value)

    }

    const coChangeContents = (event) => {
        setContents(event.target.value)

    }

    return (
        <BoardWriterUI 
            aaa={onClickSubmit} 
            bbb={onChangeWriter}
            ccc={onChangeTitle}
            ddd={coChangeContents}/>
    )
}

-컨테이너

import { gql } from "@apollo/client"


const 나의그래프큐엘셋팅 = gql`
    mutation createBoard($writer : String, $title : String, $contents: String) {
        createBoard(writer : $writer, title : $title, contents : $contents) {
            _id
            number
            message
        }
    }
` 

-쿼리

 

 

답변 1

답변을 작성해보세요.

0

안녕하세요! simple님!

마지막 사진에서 const 나의그래프큐엘셋팅 부분을 export해 주셔야 container에서 import 하실 수 있답니다!^^

simple님의 프로필

simple

질문자

2023.08.11

하... 이런 실수를 감사합니다!!

채널톡 아이콘