alphasights / ember-graphql-adapter Goto Github PK
View Code? Open in Web Editor NEWGraphQL adapter for Ember Data
License: MIT License
GraphQL adapter for Ember Data
License: MIT License
The api I'm hitting doesnt use the key 'id' for the primary key so this line causes the request to fail since there is no id. Changing it to 'uid' for instance worked but it should respect the primaryKey attribute on a serializer and if not present fall back to id.
ember-graphql-adapter/addon/parser.js
Line 23 in 51670d2
I'm trying to access GitHub's GraphQL API and as far as I can tell from the code I can't set the Authorization
header. Is that correct?
I've been unable to get this owkring using the documentation surrounding pushPayload on a model that this adapter is being used for. I keep getting an error Error: Assertion Failed: Encountered a resource object with an undefined type (resolved resource using DS.JSONAPISerializer)
also I get WARNING: heuristic fragment matching going on!
.
Thanks.
Branch | Build failing 🚨 |
---|---|
Dependency | ember-ajax |
Current Version | 3.1.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
ember-ajax is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 34 commits.
196b10f
v3.1.1
22f63a0
fix: use assign
instead of deprecated merge
3bcd571
chore(deps): update
829d82d
chore(ci): run tests against Ember 2.12+
46b7ba1
chore: remove reference to ic-ajax
826d4c3
chore: remove reference to Ember 1.13
6694fb1
chore(docs): update README
3a25d71
fix: don't append leading '/' when building url
f71854f
refactor: convert to TypeScript
23705b9
chore(deps): install and configure TypeScript
31ee07a
fix: make FastBoot test more reliable
b96b65f
test: add FastBoot test
2f58087
fix: correctly import najax
for FastBoot
ad730f9
chore(ci): update node version
d1990ea
fix: clean up some deprecation warnings
There are 34 commits in total.
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
According to the documentation for GraphQL you can use a get request with the query url encoded or a post request with a json object in the body of the request. Is there currently support for the post request format?
We're seeing that all of the relationships are passed through, which doesn't seem like it jives with GraphQL as a "only what the client needs" query language.
Is there a way I'm not seeing, or plans to be able, to specify which fields should be returned?
Thanks!
Given an ember model:
export default DS.Model.extend({
resources: DS.hasMany('resources', async: true)
});
In the case where resources is [1], the adapter assumes that the graphql api has the singular type available, and you can end up getting an error similar to:
{"0"=>"Field 'resource' doesn't exist on type 'Query'"}
This means that to make this workable, you need to make sure the API has both the singular and plural way of accessing the resource which can be quite verbose.
We should do like a TodoMVC demo with a Rails GraphQL backend. Something that we could make a deploy to heroku button for and put all the code out there for people to see how to rig everything up. The README
is a good starting place, but it'd be nice to go further with it.
The way we are handling GraphQL errors is causing issues when communicating on the front end and running respective tests.
Given the model:
export default Model.extend({
name: attr('string'),
parents: DS.hasMany('node'),
children: DS.hasMany('node')
});
The adapter generates the following query:
query node {
node(id: "my_node_id") {
id
name
parents {
id
name
children {
id
name
}
}
}
}
This seems to me to be faulty behavior, as the children should not be nested within the parents but rather be on the same level.
Hi there, would you someone familiar with the project would be open to giving an "Introduction to ember-graphql-adapter" lightning talk at an upcoming Global Ember Meetup in the beginning of next year? We'll edit the video and give you video that you can embed into the addon's README. You can see an example of other introduction videos here https://vimeo.com/album/3607049
The talk usually covers:
Documentation on how to alias models and fields would be really helpful. I think there's a way with ember-graphql-adapter
but it's unclear.
For example, say my graph has a type foo
, but I want to use bar
instead, what do I do?
Hi,
I see from this integration test that:
Post.reopen({
postCategory: DS.belongsTo('postCategory', { async: false }),
comments: DS.hasMany('comment', { async: false }),
topComments: DS.hasMany('comment', { async: false })
});
results in the following query in the test:
query author {
author(id: "1") {
id name posts {
id name
postCategory { id name }
comments { id name }
topComments: comments { id name } # <- question is regarding this
}
profile { id age }
}
}
I'm a bit puzzled by the field comments
being queried twice and aliased as topComments
once. As I understand it both Post.comments
and Post.topComments
is of type Comment
, but when querying the the server why do we query the comments
for both properties?
I think the expected behaviour would be just to drop the alias and ask the server for it's topComments field, but I'm quite new to GraphQL as I started working on it today, so I may be wrong here :-)
(I do understand that we can give arguments when query comments
and thus alias may be appropriate to use, but that doesn't seem to be the case here.)
http://graphql.org/learn/queries/#inline-fragments
I'm trying to build a query that looks something like this:
{
findByVal_ProductLookup(val: "490441202902") {
type: __typename
... on BARCODE {
brcdVal: val
someIds {
someIdVal: val
description
primaryImage
variation
}
}
}
}
it would be great to see some more complex examples of the ember implementation.
After installing as described in the Readme I found I had to change the names of the adapter and serializer from GraphQLAdapter
to Adapter
and from GraphQLSerilizer
to Serializer
.
Those original names aren't defined on the ember-graphql-adapter.
Hi, in 4f1fe16, the async
behavior works as expected. Is there any plan to release a new version soon with these? Thanks for writing this adapter btw 🍺
Currently, when constructing the queries to send to the server, the compiler uses the adapters normalizeCase function. If the server is sending attributes underscored and ember expects them camelCased, overwriting the normalizeCase function in the adapter will cause the query to succeed but multi-word attributes to not display in the ember app. To get it working I had to do something like the following in my adapter:
compile(store, type, options) {
options['normalizeCaseFn'] = this.compileNormalizeCase;
return Compiler.compile(type, store, options);
},
compileNormalizeCase: function(string) {
return underscore(string);
}
and in the serializer:
normalizeCase(string) {
return underscore(string);
}
Since the normalizeCase function in the serializer is what is normally expected to be sent to the server and the normalizeCase on the adapter is used for retrieving data from the server it would make more sense to use the serializers normalizeCase function instead of the adapters.
ember-graphql-adapter/addon/adapter.js
Line 245 in 51670d2
I am trying to write a mutation to my GraphQL server and I keep getting an error:
{"errors":[{"message":"Field "userCreate" argument "user" of type "UserInput!" is required but not provided.","locations":[{"line":1,"column":24}]}]}
And the error in the console is as follows:
TypeError: Cannot read property 'user' of undefined
Trying to install ember-graphql-adapter in a new ember project I get the following error:
$ yarn add ember-graphql-adapter
yarn add v0.27.5
[1/4] Resolving packages...
[2/4] Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version "^4.5 || 6.* || 7.*".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command
it looks like this is caused by the dependency to [email protected] which doesn't work with v8 - 6.8.2 does.
I'm trying to use your adapter, but I'm getting a this error with a mutation query:
account.js:17 createBankAccount Error: Error: Ember AJAX Request GET http://localhost:3000/graphql returned a 405
Payload (Empty Content-Type)
"GET supports only query operation"
This is the request:
context:Class {store: Class, __ember1524240476438: null}
data: {query: "mutation bankAccountCreate { bankAccount: bankAcco…r thirdParty thirdPartyPaymentAccount visible } }"}
dataType: "json"
type: "GET"
It's strange to me that a mutation is a GET
, rather than a POST
, but I assume running a query with a mutation what Apollo needs to run the correct resolvers? Regardless, my request is denied.
I've set this up using a createRecord
method and then running save
:
async createBankAccount(options) {
const bankAccount = this.store.createRecord('bankAccount', options);
try {
await bankAccount.save();
} catch (e) {
console.warn(`createBankAccount Error: ${e}`)
}
},
In your readme, it would be helpful to see the graphql sybtax that the adapters are trying to use. This will help out understand how to use for our needs.
Something like this
query
{
Media(search: "Dragonball") {
title {
userPreferred
},
description
}
}
User Model
import DS from 'ember-data';
export default DS.Model.extend({
email: DS.String,
firstname: DS.String,
lastname: DS.String
});
adapter
import GraphQLAdapter from 'ember-graphql-adapter';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import ENV from 'appmin/config/environment';
export default GraphQLAdapter.extend(DataAdapterMixin, {
authorizer: 'authorizer:oauth2',
endpoint: `${ENV.host}/graphql`
});
Route model hook
model() {
return get(this, 'store').findAll('user');
}
Query
query users { users { id } }
Why doesnt it query email, firstname and lastname?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.