Amplify-cli: Add my own query to schema?

Created on 1 Sep 2018  Â·  6Comments  Â·  Source: aws-amplify/amplify-cli

So I was trying to make a schema like so:

type Container @model @searchable {
    id: ID!
    name: String!
    containerType: String!
    description: String
    file: String
    thumb: String
    tags: [Tag] 
    containers : [Container] 
}
type Tag @model {
    id: ID!
    value: String!
    tagType: String
}
type Query {
    SketchfabGet: AWSJSON
}
schema {
    query: Query
}

But this seems not allowed.

Here is some log output:

ryan@ryan-ubuntu:~/Developer/phaas$ amplify push
| Category  | Resource name   | Operation | Provider plugin   |
| --------- | --------------- | --------- | ----------------- |
| Api       | phaas           | Update    | awscloudformation |
| Auth      | cognitof14755c1 | No Change | awscloudformation |
| Analytics | phaas           | No Change | awscloudformation |
| Storage   | phaasstorage    | No Change | awscloudformation |
? Are you sure you want to continue? true
✖ An error occurred when pushing the resources to the cloud

Cannot read property 'value' of undefined
ryan@ryan-ubuntu:~/Developer/phaas$ amplify api gql-compile
2018-08-31T23:05:46.469Z - error: uncaughtException: Cannot read property 'value' of undefined date=Fri Aug 31 2018 18:05:46 GMT-0500 (CDT), pid=10462, uid=1000, gid=1000, cwd=/home/ryan/Developer/phaas, execPath=/usr/bin/node, version=v8.11.3, argv=[/usr/bin/node, /usr/bin/amplify, api, gql-compile], rss=135823360, heapTotal=105619456, heapUsed=66442968, external=9160549, loadavg=[0.89599609375, 0.833984375, 0.7685546875], uptime=1843309, trace=[column=23, file=/private/var/folders/mk/36m2f9gx7h5bblhkkx68fv1ck8cth9/T/tmp.XVZ9RJG5/amplify-cli/packages/graphql-transformer-core/src/validation.ts, function=null, line=92, method=null, native=false, column=null, file=null, function=Array.reduce, line=null, method=reduce, native=false, column=37, file=/private/var/folders/mk/36m2f9gx7h5bblhkkx68fv1ck8cth9/T/tmp.XVZ9RJG5/amplify-cli/packages/graphql-transformer-core/src/validation.ts, function=astBuilder, line=89, method=null, native=false, column=21, file=/private/var/folders/mk/36m2f9gx7h5bblhkkx68fv1ck8cth9/T/tmp.XVZ9RJG5/amplify-cli/packages/graphql-transformer-core/src/validation.ts, function=Object.validateModelSchema, line=111, method=validateModelSchema, native=false, column=24, file=/private/var/folders/mk/36m2f9gx7h5bblhkkx68fv1ck8cth9/T/tmp.XVZ9RJG5/amplify-cli/packages/graphql-transformer-core/src/GraphQLTransform.ts, function=GraphQLTransform.transform, line=197, method=transform, native=false, column=25, file=/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/transform-graphql-schema.js, function=transformGraphQLSchema, line=97, method=null, native=false, column=null, file=null, function=null, line=null, method=null, native=false, column=7, file=internal/process/next_tick.js, function=process._tickDomainCallback, line=228, method=_tickDomainCallback, native=false], stack=[TypeError: Cannot read property 'value' of undefined,     at /private/var/folders/mk/36m2f9gx7h5bblhkkx68fv1ck8cth9/T/tmp.XVZ9RJG5/amplify-cli/packages/graphql-transformer-core/src/validation.ts:92:23,     at Array.reduce (<anonymous>),     at astBuilder (/private/var/folders/mk/36m2f9gx7h5bblhkkx68fv1ck8cth9/T/tmp.XVZ9RJG5/amplify-cli/packages/graphql-transformer-core/src/validation.ts:89:37),     at Object.validateModelSchema (/private/var/folders/mk/36m2f9gx7h5bblhkkx68fv1ck8cth9/T/tmp.XVZ9RJG5/amplify-cli/packages/graphql-transformer-core/src/validation.ts:111:21),     at GraphQLTransform.transform (/private/var/folders/mk/36m2f9gx7h5bblhkkx68fv1ck8cth9/T/tmp.XVZ9RJG5/amplify-cli/packages/graphql-transformer-core/src/GraphQLTransform.ts:197:24),     at transformGraphQLSchema (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/transform-graphql-schema.js:97:25),     at <anonymous>,     at process._tickDomainCallback (internal/process/next_tick.js:228:7)]

Is it possible for me to add a simple extra query to the schema and attach a resolver to it through Appsync UI somehow?

feature-request graphql-transformer

Most helpful comment

This use case is not yet supported but will be in the future. I will update this ticket with progress.

All 6 comments

I more or less had this same question. How to customize and extend the schema and add your own custom resolvers using the CLI? @rygo6 did you try pushing the API and then manually adding through the AWS Console? Did that work for you, or do those changes just get overridden after each push?

This use case is not yet supported but will be in the future. I will update this ticket with progress.

@chrisco255 I tried this as I wanted to extend the schema so I could have a Lambda function resolver but it gets overwritten after each push

227 Solves this and is published to NPM. Please use the latest version of the CLI to avail of this feature.

@HieronymusLex This would be solved by feature request for custom resolvers - #74

This is still not working for me. I have a query / resolvers which were automatically created by the CLI. No when I create the identical query and resolvers manually with slightly different name, there is null data returned.

+1 same issue here

Was this page helpful?
0 / 5 - 0 ratings