Skip to content

Commit

Permalink
change more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Oct 24, 2024
1 parent e9af8a8 commit 7343f00
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 100 deletions.
4 changes: 3 additions & 1 deletion client/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { GraphQLClient } from 'graphql-request';

export const API_URL = process.env.REACT_APP_API_URI;
export const graphQLClient = new GraphQLClient(API_URL!);
export const graphQLClient = new GraphQLClient(API_URL!, {
headers: { 'dgidb-client-name': 'dgidb-frontend' },
});
7 changes: 4 additions & 3 deletions client/src/hooks/queries/useGetAmbiguousResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ export function useGetMatchedResults(names: string[], type: ResultTypes) {
async () => {
const res = await graphQLClient.request(
requestQuery,
{ searchTerms: names },
{
searchTerms: names,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
'dgidb-query-type':
type === ResultTypes.Gene ? 'search-genes' : 'search-drugs',
}
);
return res;
},
Expand Down
7 changes: 4 additions & 3 deletions client/src/hooks/queries/useGetCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ export function useGetCategories(names: string[]) {
async () => {
const res = await graphQLClient.request(
getCategoriesQuery,
{ searchTerms: names },
{
searchTerms: names,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
'dgidb-query-type': 'search-genes',
'dgidb-genes-search-mode': 'categories',
}
);
return res;
},
Expand Down
10 changes: 3 additions & 7 deletions client/src/hooks/queries/useGetDrugInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ export function useGetDrugInteractions(conceptId: string) {
return useQuery(
'drug-interactions' + conceptId,
async () => {
const res = await graphQLClient.request(
getDrugInteractionsQuery,
{
conceptId,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getDrugInteractionsQuery, {
conceptId,
});
return res;
},
{ enabled: conceptId !== '' }
Expand Down
10 changes: 3 additions & 7 deletions client/src/hooks/queries/useGetDrugRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ export function useGetDrugRecord(conceptId: string) {
return useQuery(
'drug-record' + conceptId,
async () => {
const res = await graphQLClient.request(
getDrugRecordQuery,
{
conceptId,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getDrugRecordQuery, {
conceptId,
});
return res;
},
{ enabled: conceptId !== '' }
Expand Down
40 changes: 12 additions & 28 deletions client/src/hooks/queries/useGetDruggableSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ export function useGetDruggableSources(sourceType: string) {
return useQuery(
'druggable-sources' + sourceType,
async () => {
const res = await graphQLClient.request(
getDruggableSourcesQuery,
{
sourceType,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getDruggableSourcesQuery, {
sourceType,
});
return res;
},
{ enabled: sourceType !== '' }
Expand Down Expand Up @@ -85,13 +81,9 @@ export function useGetGeneSources(sourceType: string) {
return useQuery(
'gene-sources' + sourceType,
async () => {
const res = await graphQLClient.request(
getGeneSourcesQuery,
{
sourceType,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getGeneSourcesQuery, {
sourceType,
});
return res;
},
{ enabled: sourceType !== '' }
Expand Down Expand Up @@ -129,13 +121,9 @@ export function useGetDrugSources(sourceType: string) {
return useQuery(
'drug-sources' + sourceType,
async () => {
const res = await graphQLClient.request(
getDrugSourcesQuery,
{
sourceType,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getDrugSourcesQuery, {
sourceType,
});
return res;
},
{ enabled: sourceType !== '' }
Expand Down Expand Up @@ -177,13 +165,9 @@ export function useGetInteractionSources(sourceType: string) {
return useQuery(
'interaction-sources' + sourceType,
async () => {
const res = await graphQLClient.request(
getInteractionSourcesQuery,
{
sourceType,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getInteractionSourcesQuery, {
sourceType,
});
return res;
},
{ enabled: sourceType !== '' }
Expand Down
10 changes: 3 additions & 7 deletions client/src/hooks/queries/useGetGeneCountsForCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ export const useGetGeneCountsForCategories = (sourceDbNames: String[]) => {
return useQuery(
'gene-counts-for-categories',
async () => {
const res = await graphQLClient.request(
getGeneCountsForCategoriesQuery,
{
sourceDbNames: sourceDbNames,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getGeneCountsForCategoriesQuery, {
sourceDbNames: sourceDbNames,
});
return res;
},
{ enabled: true } // TODO double check
Expand Down
10 changes: 3 additions & 7 deletions client/src/hooks/queries/useGetGeneInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ export function useGetGeneInteractions(conceptId: string) {
return useQuery(
'gene-interactions' + conceptId,
async () => {
const res = await graphQLClient.request(
getGeneInteractionsQuery,
{
conceptId,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getGeneInteractionsQuery, {
conceptId,
});
return res;
},
{ enabled: conceptId !== '' }
Expand Down
10 changes: 3 additions & 7 deletions client/src/hooks/queries/useGetGeneRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ export function useGetGeneRecord(conceptId: string) {
return useQuery(
'gene-record' + conceptId,
async () => {
const res = await graphQLClient.request(
getGeneRecordQuery,
{
conceptId,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getGeneRecordQuery, {
conceptId,
});
return res;
},
{ enabled: conceptId !== '' }
Expand Down
12 changes: 4 additions & 8 deletions client/src/hooks/queries/useGetGenesForCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ export function useGetGenesForCategory(
return useQuery(
`genes-for-category-${categoryName}-db-${sourceDbNames}`,
async () => {
const res = await graphQLClient.request(
getGenesForCategoryQuery,
{
categoryName: categoryName,
sourceDbNames: sourceDbNames,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getGenesForCategoryQuery, {
categoryName: categoryName,
sourceDbNames: sourceDbNames,
});
return res;
},
{ enabled: categoryName !== '' }
Expand Down
6 changes: 1 addition & 5 deletions client/src/hooks/queries/useGetInteractionClaimTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ const getInteractionClaimTypesQuery = gql`

export function useGetInteractionClaimTypes() {
return useQuery('interaction_claim_types', async () => {
const res = await graphQLClient.request(
getInteractionClaimTypesQuery,
{},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getInteractionClaimTypesQuery, {});
return res;
});
}
10 changes: 3 additions & 7 deletions client/src/hooks/queries/useGetInteractionRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ export function useGetInteractionRecord(id: string) {
return useQuery(
id,
async () => {
const res = await graphQLClient.request(
getInteractionRecordQuery,
{
id,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getInteractionRecordQuery, {
id,
});
return res;
},
{ enabled: id !== '' }
Expand Down
10 changes: 3 additions & 7 deletions client/src/hooks/queries/useGetInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ export function useGetInteractionsByGenes(names: string[]) {
return useQuery(
'interactions' + names,
async () => {
const res = await graphQLClient.request(
getInteractionsByGenesQuery,
{
names,
},
{ 'dgidb-client-name': 'dgidb-frontend' }
);
const res = await graphQLClient.request(getInteractionsByGenesQuery, {
names,
});
return res;
},
{ enabled: names.length > 0 }
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/queries/useGetNameSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useGetNameSuggestions(searchTerm: string, type: SearchTypes) {
const res = await graphQLClient.request(
query,
{ term: searchTerm },
{ 'dgidb-client-name': 'dgidb-frontend' }
{ 'dgidb-query-type': queryName }
);
return res;
},
Expand Down
5 changes: 3 additions & 2 deletions server/app/controllers/concerns/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module Analytics
extend ActiveSupport::Concern

def get_trace_mode(request)
return unless Rails.env.production?
# return unless Rails.env.production?

if request.headers['dgidb-client-name'] == 'dgidb-frontend'
query_types = %w[search-genes search-drugs]
if request.headers['dgidb-client-name'] == 'dgidb-frontend' && query_types.include?(request.headers['dgidb-query-type'])
:frontend_analytics
elsif request.headers['RAW_POST_DATA'] && !request.headers['RAW_POST_DATA'].include?('IntrospectionQuery')
:api_analytics
Expand Down

0 comments on commit 7343f00

Please sign in to comment.