Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access context value in the graphql query #307

Open
biboswan-sentinelone opened this issue Jun 7, 2023 · 0 comments
Open

Unable to access context value in the graphql query #307

biboswan-sentinelone opened this issue Jun 7, 2023 · 0 comments

Comments

@biboswan-sentinelone
Copy link

biboswan-sentinelone commented Jun 7, 2023

export function HttpClientProvider({ baseURL, token, scopeRecord, children }: HttpClientProviderProps) {
  const authLink = new ApolloLink((operation, forward) => {
    operation.setContext(({ headers = {} }) => ({
      headers: {
        ...headers,
        [CSRF_TOKEN]: token,
      },
    }));

    return forward(operation);
  });

  const setScopeLink = setContext((request, previousContext) => {
   console.log('sc',scopeRecord);
    return { ...previousContext, scopeRecord };
  });

  const restLink = new RestLink({
    uri: baseURL,
  });

  const client = new ApolloClient({
    cache: new InMemoryCache(),
    link: ApolloLink.from([authLink, setScopeLink, restLink]),
  });

  return <ApolloProvider client={client}>{children}</ApolloProvider>;
}
export const ABC= gql`
    query listPolicies($limit: Int, $skip: Int, $sortedColumn: SortedColumn, $filter: PolicyFilter) {
        listPolicies(limit: $limit, skip: $skip, sortedColumn: $sortedColumn, filter: $filter)
            @rest(type: "TYPEA", path: "${SERVICE_BASE_PATH}?{args}&{context.scopeRecord}", method: "GET") {
                data
            }
    }
`;

context.scopeRecord is coming undefined although in the console.log(scopeRecord) I see the value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant