# Configure the client

The `getSDK` gives you an SDK client for your GraphQL API

{% code overflow="wrap" lineNumbers="true" %}

```typescript
import { GraphQLClient } from "graphql-request";
import { getSdk } from "../graphqlSDKGenerator/graphqlSDKGenerator";

const initializeSDK = () => {
  const client = new GraphQLClient(
    "https://your-end-point/",
    {
      headers: {
        Authorization: 'Bearer xxx',
      },
    }
  );

  return getSdk(client);
};

const main = async () => {
  const sdkInstance = initializeSDK();
};

main();


```

{% endcode %}

### Custom logger

We can pass a custom function which can be used to log the output and help in debugging. You can [check live example here](https://github.com/Siddharth9890/space-x-graphql-example/blob/main/src/clientWrapper.ts).

{% code lineNumbers="true" %}

```typescript
import { GraphQLClient } from "graphql-request";
import { getSdk, SdkFunctionWrapper } from "../graphqlSDKGenerator/graphqlSDKGenerator";

const clientTimingWrapper: SdkFunctionWrapper = async <T>(
  action: () => Promise<T>,
  operationName: string,
  operationType?: string
): Promise<T> => {
  const startTime = new Date();
  const result: Awaited<T> = await action();
  console.log(
    `YOUR_SDK ${Object.keys(result as any)[0]} ${operationType} took ${
      (new Date() as any) - (startTime as any)
    } (ms)`
  );
  return result;
};

const initializeSDK = () => {
  const client = new GraphQLClient(
    "https://your-end-point/",
    {
      headers: {
        Authorization: 'Bearer xxx',
      },
    }
  );

  return getSdk(client,clientTimingWrapper);
};

const main = async () => {
  const sdkInstance = initializeSDK();
};

main();


```

{% endcode %}

### Pass dynamic headers at runtime

You can pass a function to the headers field to pull the headers at query time, this way you can make requests if user changes during the session.

{% code lineNumbers="true" %}

```typescript
import { GraphQLClient } from "graphql-request";
import { getSdk } from "../graphqlSDKGenerator/graphqlSDKGenerator";

const initializeSDK = (authToken:string) => {
  const client = new GraphQLClient(
    "https://your-end-point/",
    {
      headers: {
        Authorization: `Bearer ${authToken}`,
      },
    }
  );

  return getSdk(client);
};

const main = async () => {
  let sdkInstance = initializeSDK(authToken);
  
  // after some operations 
  user.logout()
  // again user logs in
  sdkInstance = initializeSDK(authToken)
};

main();


```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.siddharth9890.com/graphql-sdk-generator/usage/configure-the-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
