Magidoc

Using the CoCore API from Rust

To assist Rust developers in integrating with the CoCore GraphQL API, here's a comprehensive guide utilizing the graphql-client crate.

1. Add Dependencies

Begin by adding the necessary dependencies to your Cargo.toml file:

    
  

2. Download the GraphQL Schema

To generate Rust types corresponding to your GraphQL queries, you'll need the GraphQL schema. You can obtain it using various tools, including the graphql-client CLI. Ensure the schema is saved as schema.graphql in your project directory.

3. Define GraphQL Queries

Create a .graphql file (e.g., src/queries/get_job.graphql ) containing your GraphQL query:

    
  

4. Generate Rust Types

Use the graphql-client procedural macro to generate Rust types for your query. In your Rust code, define a module that references your schema and query:

    
  

This will generate a module named get_job_query containing the necessary types.

5. Initialize the GraphQL Client

Set up the reqwest client with the appropriate headers, including your API key:

    
  

6. Execute Queries and Handle Responses

Construct the variables for your query, send the request, and handle the response:

    
  

7. Putting It All Together

Here's how you can integrate the above components:

    
  

8. Explore API Documentation

For detailed information on available queries, mutations, and schema definitions, refer to the CoCore API documentation at https://docs.wearecococo.com .

By following these steps, Rust developers can effectively integrate with the CoCore GraphQL API using the graphql-client crate.