Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi和Graph.cool API?_Delphi_Facebook Graph Api_Graphql_Graphcool - Fatal编程技术网

Delphi和Graph.cool API?

Delphi和Graph.cool API?,delphi,facebook-graph-api,graphql,graphcool,Delphi,Facebook Graph Api,Graphql,Graphcool,如何使用Delphi接口Graph.cool 我想构建一个Win32/Win32/OSX客户端 具有GraphQL(REST)API端点 例如: 使用FaceBook GraphQL实现GraphQL的一个已知示例位于: 我有一个查询示例: mutation { createUser( authProvider: { email: { email: "hello@hello.com", password: "hello" }} ) {

如何使用Delphi接口Graph.cool

我想构建一个Win32/Win32/OSX客户端

具有GraphQL(REST)API端点

例如:

使用FaceBook GraphQL实现GraphQL的一个已知示例位于:

我有一个查询示例:

mutation {
  createUser(
    authProvider: { 
      email: { email: "hello@hello.com", password: "hello" 
      }}
  )
  {
    id
  }
}
创建一个用户帐户

我尝试使用TRestClient,但似乎没有办法放置非结构化字符串查询

DFM的Snipplet:

var
  RESTRequest1: TRESTRequest;
  RESTRequest1 := TRESTRequest.Create(Self);
  RESTRequest1.Name := 'RESTRequest1';
  RESTRequest1.AcceptEncoding := ' ';
  RESTRequest1.Client := RESTClient1;
  RESTRequest1.Method := rmPOST;
  with RESTRequest1.Params.Add do begin 
    name := 'query';
    Options := [poAutoCreated];
    Value := '{ "query": "mutation { createUser(authProvider: { email: { email: \"hello@hello\", password: \"hello\" } }) { id } }" }';
    ContentType := ctAPPLICATION_JAVASCRIPT;
  end;
  with RESTRequest1.Params.Add do begin 
    name := ' id ';
    Options := [poAutoCreated];
  end;
  RESTRequest1.Response := RESTResponse1;
  RESTRequest1.SynchronizedEvents := False;
我得到:a)错误的请求,b)无效的Json查询


我想知道如何与Graph.cool API接口吗?

简单的方法是直接使用HttpClient,如

function SendHttp(const ARequest: string): string;
var
  HttpClient: THttpClient;
  Response: IHttpResponse;
  ST: TStream;
begin
  HttpClient := THttpClient.Create;
  try
    HttpClient.ContentType := CONTENTTYPE_APPLICATION_JSON;
    HttpClient.Accept := CONTENTTYPE_APPLICATION_JSON;
    ST := TStringStream.Create(ARequest);
    try
      Response := HttpClient.Post('https://api.graph.cool/simple/v1/ENDPOINT', ST, nil,
      TNetHeaders.Create(
        TNameValuePair.Create('Authorization', 'Bearer YOUR_AUTH_TOKEN')
       ));
      Result := Response.ContentAsString();
    finally
      ST.Free;
    end;
  finally
    HttpClient.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Add(SendHttp('{"query": "mutation {'+
      '  createUser('+
      '    authProvider: {' +
      '      email: { email: \"hello@hello.com\", password: \"hello\"'+
      '      }}'+
      '  )' +
      '  {' +
      '    id' +
      '  }' +
      '}" }'));
end;

您将如何使用此repo-获取JWT声明并使用Graph.cool进行身份验证?例如,如果是登录:Memo1.Lines.Add(SendHttp(“{”query):“mutation”+{signinUser(“+”email:{email:\”hello@hello.com\,密码:\'hello\'}{token}}');我做了更多的工作。如果您获得JWT认证令牌,您可以a)使用Delphi JWT解码令牌,或者将JWT认证令牌原样传递回网站。会有用的。