Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom scalar types should be listed in typesUsed #40

Closed
sav007 opened this issue Jan 24, 2017 · 4 comments
Closed

Custom scalar types should be listed in typesUsed #40

sav007 opened this issue Jan 24, 2017 · 4 comments

Comments

@sav007
Copy link

sav007 commented Jan 24, 2017

Android GraphQL requires custom scalar types to be listed in typesUsed array in IR.json file.
Custom scalar type should be defined in the same way as enum types. This definitions will be later used by android code generator and response adapters

For example:

"typesUsed": [
    {
      "kind": "???",
      "name": "Date",
      "description": "DateTime value"
    },
    {
      "kind": "EnumType",
      "name": "Episode",
      "description": "The episodes in the Star Wars trilogy",
      "values": [
        {
          "name": "NEWHOPE",
          "description": "Star Wars Episode IV: A New Hope, released in 1977."
        },
        {
          "name": "EMPIRE",
          "description": "Star Wars Episode V: The Empire Strikes Back, released in 1980."
        },
        {
          "name": "JEDI",
          "description": "Star Wars Episode VI: Return of the Jedi, released in 1983."
        }
      ]
    }
@sav007
Copy link
Author

sav007 commented Jan 31, 2017

@martijnwalraven just checked and not sure that the fix works:

So I have next custom scalar type in my schema:

{
          "kind": "SCALAR",
          "name": "DateTime",
          "description": null,
          "fields": null,
          "inputFields": null,
          "interfaces": null,
          "enumValues": null,
          "possibleTypes": null
        }

Product type:

"kind": "OBJECT",
          "name": "Product",
          "description": null,
          "fields": [
            ...
            {
              "name": "createdAt",
              "description": null,
              "args": [],
              "type": {
                "kind": "NON_NULL",
                "name": null,
                "ofType": {
                  "kind": "SCALAR",
                  "name": "DateTime",
                  "ofType": null
                }
              },
              "isDeprecated": false,
              "deprecationReason": null
            },

Query:

query ShopWithDate {
  shop {
    products(first:50) {
      edges {
        node {
          title
          createdAt
        }
      }
    }
  }
}

Generated IR.json

{
	"operations": [
		{
			"operationName": "ShopWithDate",
			"operationType": "query",
			"variables": [],
			"source": "query ShopWithDate {\n  shop {\n    products(first: 50) {\n      edges {\n        node {\n          title\n          createdAt\n        }\n      }\n    }\n  }\n}",
			"fields": [
				{
					"responseName": "shop",
					"fieldName": "shop",
					"type": "Shop!",
					"fields": [
						{
							"responseName": "products",
							"fieldName": "products",
							"type": "ProductConnection!",
							"fields": [
								{
									"responseName": "edges",
									"fieldName": "edges",
									"type": "[ProductEdge!]!",
									"fields": [
										{
											"responseName": "node",
											"fieldName": "node",
											"type": "Product!",
											"fields": [
												{
													"responseName": "title",
													"fieldName": "title",
													"type": "String!"
												},
												{
													"responseName": "createdAt",
													"fieldName": "createdAt",
													"type": "DateTime!"
												}
											],
											"fragmentSpreads": [],
											"inlineFragments": []
										}
									],
									"fragmentSpreads": [],
									"inlineFragments": []
								}
							],
							"fragmentSpreads": [],
							"inlineFragments": []
						}
					],
					"fragmentSpreads": [],
					"inlineFragments": []
				}
			],
			"fragmentsReferenced": []
		}
	],
	"fragments": [],
	"typesUsed": []
}

"typesUsed": [] - is empty

@martijnwalraven
Copy link
Contributor

Are you sure you are running the latest version of apollo-codegen?

@sav007
Copy link
Author

sav007 commented Jan 31, 2017

will check again, with npm I'm not sure about anything :)

@sav007
Copy link
Author

sav007 commented Feb 1, 2017

yes it works fine

ecstasy2 added a commit to ecstasy2/apollo-codegen that referenced this issue Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants