Every line of 'axios graphql' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
58 export function graphql(query, options, ...rest) { 59 // The first definition is the main operation 60 const { operation } = query.definitions[0]; 61 if (operation !== 'mutation') { 62 return (Component) => apolloGraphql(query, options, ...rest)(Component); 63 } 64 else if ( ! options || ! options.name && operation === 'mutation') { 65 console.warn('Mutation detected without a explicit name. No redux actions will be dispatched.'); 66 return (Component) => apolloGraphql(query, options, ...rest)(Component); 67 } 68 else { 69 return (Component) => { 70 const Result = compose( 71 connect(), 72 apolloGraphql(query, options, ...rest), 73 reduxGraphql(options), 74 )(Component); 75 return hoistNonReactStatics(Result, Component); 76 }; 77 } 78 }
11 export function graphql(request, query, options) { 12 options = 13 typeof query === "string" 14 ? (options = Object.assign({ query }, options)) 15 : (options = query); 16 const requestOptions = Object.keys(options).reduce((result, key) => { 17 if (NON_VARIABLE_OPTIONS.includes(key)) { 18 result[key] = options[key]; 19 return result; 20 } 21 if (!result.variables) { 22 result.variables = {}; 23 } 24 result.variables[key] = options[key]; 25 return result; 26 }, {}); 27 return request(requestOptions).then((response) => { 28 if (response.data.errors) { 29 throw new GraphqlError(requestOptions, { 30 data: response.data, 31 }); 32 } 33 return response.data.data; 34 }); 35 }
7 function graphql (request, query, options) { 8 if (typeof query === 'string') { 9 options = Object.assign({ query }, options) 10 } else { 11 options = query 12 } 13 14 const requestOptions = Object.keys(options).reduce((result, key) => { 15 if (NON_VARIABLE_OPTIONS.includes(key)) { 16 result[key] = options[key] 17 return result 18 } 19 20 if (!result.variables) { 21 result.variables = {} 22 } 23 24 result.variables[key] = options[key] 25 return result 26 }, {}) 27 28 return request(requestOptions) 29 .then(response => { 30 if (response.data.errors) { 31 throw new GraphqlError(requestOptions, response) 32 } 33 34 return response.data.data 35 }) 36 }
81 export function callGraphQL({ query, variables = {}, headers = {} } : { query : string, variables? : { [string] : mixed }, headers? : { [string] : string } }) : ZalgoPromise { 82 return request({ 83 url: GRAPHQL_URI, 84 method: 'POST', 85 json: { 86 query, 87 variables 88 }, 89 headers: { 90 'x-app-name': SMART_PAYMENT_BUTTONS, 91 ...headers 92 } 93 }).then(({ status, body }) => { 94 const errors = body.errors || []; 95 96 if (errors.length) { 97 const message = errors[0].message || JSON.stringify(errors[0]); 98 throw new Error(message); 99 } 100 101 if (status !== 200) { 102 throw new Error(`${ GRAPHQL_URI } returned status ${ status }`); 103 } 104 105 return body.data; 106 }); 107 }
39 graphql(query, variables = {}) { 40 const url = 'https://api.github.com/graphql' 41 const options = { 42 body: JSON.stringify({ query, variables }), 43 method: 'POST', 44 headers: this.getHeaders(), 45 } 46 47 return fetch(url, options).then(response => { 48 console.log(`${response.status} ${JSON.stringify(variables)}`) 49 50 if (!response.ok) { 51 return response.json().then(json => { 52 throw new Error(`${response.status}: ${JSON.stringify(json)}`) 53 }) 54 } 55 56 return response.json().then(result => { 57 if (result.errors) { 58 throw new Error(`GraphQL Error: ${result.errors.map(e => e.message).join(', ')}`) 59 } 60 61 return result.data 62 }) 63 }) 64 }
15 export async function requestGraphQL( 16 query: string, 17 variables: any = {}, 18 { instanceUrl, accessToken }: Options 19 ): Promise<{ data?: any; errors?: { message: string; path: string }[] }> { 20 const headers: Record = { 21 Accept: 'application/json', 22 'Content-Type': 'application/json', 23 'User-Agent': 'TypeScript language server', 24 } 25 if (accessToken) { 26 headers.Authorization = 'token ' + accessToken 27 } 28 const response = await got.post(new URL('/.api/graphql', instanceUrl), { 29 headers, 30 body: { query, variables }, 31 json: true, 32 }) 33 return response.body 34 }
24 export function* fetchGraphQL(query) { 25 const { graphQLUrl, token } = yield call(getGqlParams); 26 const response = yield call(fetchGraphQLApi, { 27 endpoint: graphQLUrl, 28 query, 29 token 30 }); 31 return response; 32 }
17 graphql(queryHash, variables = {}) { 18 return this.http.get('/graphql/query/', { 19 qs: { 20 query_hash: queryHash, 21 variables: JSON.stringify(variables), 22 }, 23 }); 24 }
64 export function graphql( 65 argsOrSchema, 66 source, 67 enableDefer, 68 rootValue, 69 contextValue, 70 variableValues, 71 operationName, 72 fieldResolver, 73 ) { 74 /* eslint-enable no-redeclare */ 75 // Always return a Promise for a consistent API. 76 return new Promise(resolve => 77 resolve( 78 // Extract arguments from object args if provided. 79 arguments.length === 1 80 ? graphqlImpl( 81 argsOrSchema.schema, 82 argsOrSchema.source, 83 argsOrSchema.enableDefer, 84 argsOrSchema.rootValue, 85 argsOrSchema.contextValue, 86 argsOrSchema.variableValues, 87 argsOrSchema.operationName, 88 argsOrSchema.fieldResolver, 89 ) 90 : graphqlImpl( 91 argsOrSchema, 92 source, 93 enableDefer, 94 rootValue, 95 contextValue, 96 variableValues, 97 operationName, 98 fieldResolver, 99 ), 100 ), 101 ); 102 }
60 function requestGraphQL(options: { 61 request: string 62 variables: {} 63 }): Observable> { 64 return from(background.requestGraphQL(options)) 65 }