如何使用GraphQL保存Draft.js数据

时间:2017-11-25 09:05:41

标签: reactjs graphql apollo draftjs

我搜索过高低。但是,我确实找到了如何convertToRawconvertFromRaw。那很好但是,如何使用GraphQL发送原始数据?

选项1:

首先想到的是,只需使用JSON.stringify(..),创建GraphQLString并发送即可。繁荣!完成!嗯......不是这样。如果我走这条路线,GraphQL期望该值是双引号,我得到关于unexpected token '等的错误。

选项2:

发送并使用GraphQLInputObjectType。这可行但是......你必须在blocks数组中写出所有这些键。不!我的第六感告诉我JSON.stringify(..)有更好的方法,但......怎么样?

以下是使用convertToRaw的数据外观的直观表示: enter image description here

传递给GraphQLString的字符串:

"{"entityMap":{},"blocks":[{"key":"7iq9s","text":"This is the type of text to pass to db via GraphQL","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}}]}"
  

“语法错误GraphQL请求(29:36)预期:,

没有convertToRaw

{"entityMap":{},"blockMap":{"bk8ro":{"key":"bk8ro","type":"unstyled","text":"This is the type of text to pass to db via GraphQL","characterList":[{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null},{"style":[],"entity":null}],"depth":0,"data":{}}},"selectionBefore":{"anchorKey":"bk8ro","anchorOffset":0,"focusKey":"bk8ro","focusOffset":0,"isBackward":false,"hasFocus":true},"selectionAfter":{"anchorKey":"bk8ro","anchorOffset":50,"focusKey":"bk8ro","focusOffset":50,"isBackward":false,"hasFocus":true}}

1 个答案:

答案 0 :(得分:1)

我想我可以在经过一些研究后回答这个问题。这个答案使用atob() and btoa()

将值传递给VIRTUALSERVER_BLA args,即11/25/2017 16:07:44 pyTSon.PluginHost.infoData Error Error calling infoData of python plugin Extended Info: Traceback (most recent call last): File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\pluginhost.py", line 476, in infoData data = p.infoData(schid, aid, atype) File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\info\__init__.py", line 160, in infoData return self.getServerInfo(schid) File "C:/Users/blusc/AppData/Roaming/TS3Client/plugins/pyTSon/scripts\info\__init__.py", line 148, in getServerInfo i.append('{0}: {1}'.format(var.__name__, var)) AttributeError: 'int' object has no attribute '__name__'

  1. 使用GraphQLString's
  2. 转换Draft.js
  3. JSON.stringify()结果
  4. 使用btoa()
  5. 这样你就会得到一个很长的字符串:content

    要解码,请使用convertToRaw,JSON.parse()Q29udGVudFN0YXRlIHsgImVudGl0eU1hcCI6IFtvYmplY3QgT2JqZWN0...etc convertFromRaw`。可能有一种更简单的方法,但现在,这是有效的。我相信这些步骤可以减少。