UNPKG

@dww/graphiql-code-exporter

Version:

Export working code snippets from GraphiQL queries

20 lines (17 loc) 948 B
import capitalizeFirstLetter from '../../utils/capitalizeFirstLetter'; export default { language: 'Ruby', name: 'graphql-client', prismLanguage: 'ruby', options: [], generate: function generate(_ref) { var serverUrl = _ref.serverUrl, variableName = _ref.variableName, operationType = _ref.operationType, operationName = _ref.operationName, operation = _ref.operation, options = _ref.options; var queryName = capitalizeFirstLetter(operationName) + capitalizeFirstLetter(operationType); return '\nrequire "graphql/client"\nrequire "graphql/client/http"\n\nServerUrl = "' + serverUrl + '"\nHTTP = GraphQL::Client::HTTP.new(ServerUrl)\nSchema = GraphQL::Client.load_schema(HTTP)\nClient = GraphQL::Client.new(schema: Schema, execute: HTTP)\n\n' + queryName + ' = Client.parse <<-\'GRAPHQL\'\n' + operation + '\nGRAPHQL\n\n\nresult = Client.query(' + queryName + ')\nputs(result)'; } };