@apollo-elements/lib
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -6,2 +6,14 @@ # Change Log | ||
# [3.3.0](https://github.com/apollo-elements/apollo-elements/compare/@apollo-elements/lib@3.2.0...@apollo-elements/lib@3.3.0) (2020-10-25) | ||
### Features | ||
* **components:** generate simple client ([dacdefc](https://github.com/apollo-elements/apollo-elements/commit/dacdefc77b7d86ecea3f59e0fb8143870ea38573)) | ||
* **mixins:** query the DOM for variables ([2df637e](https://github.com/apollo-elements/apollo-elements/commit/2df637e1babd35b5e0dc3af9d2de11f03e920938)) | ||
# [3.2.0](https://github.com/apollo-elements/apollo-elements/compare/@apollo-elements/lib@3.1.1...@apollo-elements/lib@3.2.0) (2020-10-21) | ||
@@ -8,0 +20,0 @@ |
@@ -1,11 +0,3 @@ | ||
/** | ||
* Is it a `<script type="application/graphql">` | ||
*/ | ||
export declare function isGraphQLScript(el: Element): boolean; | ||
/** | ||
* Get the child of the element that is a graphql script | ||
*/ | ||
export declare function getGraphQLScriptChild(el: HTMLElement): HTMLScriptElement; | ||
export declare function stripUndefinedValues<X>(o: X): X; | ||
/** Splits a string by `,` then trims each of the results */ | ||
export declare function splitCommasAndTrim(value: string): string[]; |
@@ -1,19 +0,1 @@ | ||
const scriptSelector = 'script[type="application/graphql"]'; | ||
/** | ||
* Is it a `<script type="application/graphql">` | ||
*/ | ||
export function isGraphQLScript(el) { | ||
var _a, _b; | ||
return (el instanceof HTMLScriptElement && | ||
((_b = (_a = el.getAttribute('type')) === null || _a === void 0 ? void 0 : _a.toLowerCase) === null || _b === void 0 ? void 0 : _b.call(_a)) === 'application/graphql'); | ||
} | ||
/** | ||
* Get the child of the element that is a graphql script | ||
*/ | ||
export function getGraphQLScriptChild(el) { | ||
if (!(el instanceof HTMLElement)) | ||
return null; | ||
else | ||
return el.querySelector(scriptSelector); | ||
} | ||
const valueIsDefined = ([, v]) => v !== undefined; | ||
@@ -20,0 +2,0 @@ export function stripUndefinedValues(o) { |
import { expect } from '@open-wc/testing'; | ||
import { isGraphQLScript, getGraphQLScriptChild, stripUndefinedValues, } from './helpers'; | ||
describe('[lib] isGraphQLScript', function () { | ||
it('validates valid script', function () { | ||
const validScript = document.createElement('script'); | ||
validScript.setAttribute('type', 'application/graphql'); | ||
expect(isGraphQLScript(validScript)).to.be.true; | ||
}); | ||
it('invalidates invalid script', function () { | ||
const invalid = document.createElement('script'); | ||
invalid.setAttribute('type', 'text/javascript'); | ||
expect(isGraphQLScript(invalid)).to.be.false; | ||
}); | ||
}); | ||
describe('[lib] getGraphQLScriptChild', function () { | ||
it('gets a graphql script child', function () { | ||
const doc = `query foo { bar }`; | ||
const element = document.createElement('div'); | ||
element.innerHTML = `<script type="application/graphql">${doc}</script>`; | ||
expect(getGraphQLScriptChild(element)).to.equal(element.firstElementChild); | ||
}); | ||
it('returns null otherwise', function () { | ||
const element = document.createElement('div'); | ||
element.innerHTML = `<script></script>`; | ||
expect(getGraphQLScriptChild(element)).to.be.null; | ||
}); | ||
}); | ||
import { stripUndefinedValues } from './helpers'; | ||
describe('[lib] stripUndefinedValues', function () { | ||
@@ -29,0 +4,0 @@ it('strips undefined values', function () { |
import { expect } from '@open-wc/testing'; | ||
import { | ||
isGraphQLScript, | ||
getGraphQLScriptChild, | ||
stripUndefinedValues, | ||
} from './helpers'; | ||
import { stripUndefinedValues } from './helpers'; | ||
describe('[lib] isGraphQLScript', function() { | ||
it('validates valid script', function() { | ||
const validScript = document.createElement('script'); | ||
validScript.setAttribute('type', 'application/graphql'); | ||
expect(isGraphQLScript(validScript)).to.be.true; | ||
}); | ||
it('invalidates invalid script', function() { | ||
const invalid = document.createElement('script'); | ||
invalid.setAttribute('type', 'text/javascript'); | ||
expect(isGraphQLScript(invalid)).to.be.false; | ||
}); | ||
}); | ||
describe('[lib] getGraphQLScriptChild', function() { | ||
it('gets a graphql script child', function() { | ||
const doc = `query foo { bar }`; | ||
const element = document.createElement('div'); | ||
element.innerHTML = `<script type="application/graphql">${doc}</script>`; | ||
expect(getGraphQLScriptChild(element)).to.equal(element.firstElementChild); | ||
}); | ||
it('returns null otherwise', function() { | ||
const element = document.createElement('div'); | ||
element.innerHTML = `<script></script>`; | ||
expect(getGraphQLScriptChild(element)).to.be.null; | ||
}); | ||
}); | ||
describe('[lib] stripUndefinedValues', function() { | ||
@@ -38,0 +5,0 @@ it('strips undefined values', function() { |
@@ -1,23 +0,1 @@ | ||
const scriptSelector = 'script[type="application/graphql"]'; | ||
/** | ||
* Is it a `<script type="application/graphql">` | ||
*/ | ||
export function isGraphQLScript(el: Element): boolean { | ||
return ( | ||
el instanceof HTMLScriptElement && | ||
el.getAttribute('type')?.toLowerCase?.() === 'application/graphql' | ||
); | ||
} | ||
/** | ||
* Get the child of the element that is a graphql script | ||
*/ | ||
export function getGraphQLScriptChild(el: HTMLElement): HTMLScriptElement { | ||
if (!(el instanceof HTMLElement)) | ||
return null; | ||
else | ||
return el.querySelector(scriptSelector); | ||
} | ||
const valueIsDefined = | ||
@@ -24,0 +2,0 @@ ([, v]): boolean => v !== undefined; |
export { hasAllVariables } from './has-all-variables'; | ||
export { getGraphQLScriptChildDocument } from './get-graphql-script-child-document'; | ||
export { gqlFromInnerText } from './gql-from-inner-text'; | ||
export { isValidGql } from './is-valid-gql'; | ||
export { isClientOperation } from './is-client-operation'; |
export { hasAllVariables } from './has-all-variables'; | ||
export { getGraphQLScriptChildDocument } from './get-graphql-script-child-document'; | ||
export { gqlFromInnerText } from './gql-from-inner-text'; | ||
export { isValidGql } from './is-valid-gql'; | ||
export { isClientOperation } from './is-client-operation'; | ||
//# sourceMappingURL=index.js.map |
export { hasAllVariables } from './has-all-variables'; | ||
export { getGraphQLScriptChildDocument } from './get-graphql-script-child-document'; | ||
export { gqlFromInnerText } from './gql-from-inner-text'; | ||
export { isValidGql } from './is-valid-gql'; | ||
export { isClientOperation } from './is-client-operation'; |
{ | ||
"name": "@apollo-elements/lib", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Library functions for apollo-elements", | ||
"main": "index.js", | ||
"module": "index.js", | ||
"type": "module", | ||
"typings": "index.d.ts", | ||
"exports": [ | ||
"./index.js", | ||
"./helpers.js", | ||
"./has-all-variables.js", | ||
"./is-client-operation.js", | ||
"./is-valid-gql.js" | ||
], | ||
"scripts": { | ||
@@ -40,3 +49,3 @@ "prepublishOnly": "tsc -b .", | ||
}, | ||
"gitHead": "3900a8266f673ddeb07f7a0f65398b8ee0774a7c" | ||
"gitHead": "87b018f7d76920263a1b92ed90493806ccaf0344" | ||
} |
@@ -9,16 +9,20 @@ # @apollo-elements/lib | ||
## getGraphQLScriptChildDocument | ||
Gets the gql-parsed DocumentNode from a direct `<script type="application/graphql">` child of an element. | ||
## createApolloClient | ||
Creates a simple ApolloClient instance given a URI and some params. | ||
```ts | ||
function getGraphQLScriptChildDocument(element: HTMLElement): DocumentNode | null; | ||
createApolloClient({ | ||
uri: '/graphql', | ||
typePolicies: { | ||
User: { | ||
fields: { | ||
fullName(_, { readField }) { | ||
return `${readField('firstName')} ${readField('lastName')}`; | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
``` | ||
## gqlFromInnerText | ||
Gets an element's `innerText` and parses it as GraphQL. | ||
```ts | ||
function gqlFromInnerText(element: HTMLScriptElement): DocumentNode | null | ||
``` | ||
## hasAllVariables | ||
@@ -25,0 +29,0 @@ Predicate that validates a GraphQL request (a `DocumentNode` and a variables object) as having all of its required (i.e. non-nullable) variables defined. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47
Yes
71426
49
966