GraphQL query client with Fetch
FetchQL is an query client for GraphQL server works on both browser and Node(need fetch support, eg. node-fetch)
var Query = new FetchQL({url: ''})
You may pass url in parameters or set it later.
Query.query({operationName: '', query: '', variables: '{}'})
=> Promise
Method for query data from the server. operationName
must be provided.
query
and variables
are followed the specification fo GraphQL.
If any errors exists(from query response), will reject the promise.
Query.getEnumTypes(['array', 'of', 'enum', 'name'])
=> Promise
Will get enums' information from server. Then you can get a following Object in promise:
{ array: { name: '', kind: '', description: '', enumValues: { name: '', description: '', } }, of: {...}, enum: {...}, name: {...} }
This method currently support caching. All enum will be cached after first querying.
Return current server address.
Query.setUrl('')
Set a new server address.
index.js
in any ES2015 environment. index.mjs
for Node (version >= 6.0) without babel, because Node does support ES2015 modules natively. You may use graphql-intro
as an develop server-side.
The MIT License (MIT)
Copyright (c) 2016 Cheng Gu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.